2 Replies - 977 Views - Last Post: 12 May 2012 - 09:56 PM Rate Topic: -----

#1 deeincredible   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-May 12

Payroll calculator only displaying "0"

Posted 12 May 2012 - 09:36 PM

I am having trouble running this code. It compiles but when I input the numbers for "Enter hourly wage" and "Enter hours worked" and then hit calculate it gives an answer of "0" each time.
import java. applet.*;
import java.awt.*;
import java.awt.event.*;

public class KilowattApplet extends Applet implements ActionListener
{
	//declare variables
	int wage, hours, pay, hoursPerPayPeriod;

	//construct components
	Label welcome = new Label("\tSIMPLE PAYROLL CALCULATOR");
	Label wageLabel = new Label("\tEnter hourly wage: ");
		TextField wageField = new TextField(5);
	Label hoursPerPayPeriodLabel = new Label("\tEnter hours worked: ");
		TextField hoursPerPayPeriodField = new TextField(5);
	Button calcButton = new Button("\t\tCalculate");
	Label outputLabel = new Label("\t\tClick the Calculate button to display amount earned");

	public void init()
	{
		setForeground(Color.blue);
		add(welcome);
		add(wageLabel);
		add(wageField);
		add(hoursPerPayPeriodLabel);
		add(hoursPerPayPeriodField);
		add(calcButton);
		calcButton.addActionListener(this);
		add(outputLabel);
	}

	public void actionPerformed(ActionEvent e)
	{
		wage = Integer.parseInt(wageField.getText());
		hours = Integer.parseInt(hoursPerPayPeriodField.getText());
		pay= wage*hoursPerPayPeriod;
		outputLabel.setText("Your gross income is $" + pay);
	}

}



Is This A Good Question/Topic? 0
  • +

Replies To: Payroll calculator only displaying "0"

#2 GregBrannon   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2250
  • View blog
  • Posts: 5,340
  • Joined: 10-September 10

Re: Payroll calculator only displaying "0"

Posted 12 May 2012 - 09:50 PM

Try line 36:
pay= wage*hours;
Was This Post Helpful? 1
  • +
  • -

#3 deeincredible   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-May 12

Re: Payroll calculator only displaying "0"

Posted 12 May 2012 - 09:56 PM

It worked! Thanks! I was mixing up "hoursPerPayPeriod" with "hours"
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1