i need help with this program any fixers appreciated?






import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;

public class GrossPay extends Applet implements ActionListener {

Label prompt;
TextField input;
TextField input2;
TextField outp;
int hours;
int pay;
int total;


public void init()
{
prompt = new Label ("Enter hours and rate and press enter");
input = new TextField(10);
input2 = new TextField(10);
outp = new TextField(10);

add(prompt);
add(input);
add(outp);
pay = 0;

}

public void actionPerformed(ActionEvent e)
{
//this is what i am supposed to use to read in double
//double rtf;
// Double rtemp=new Double(textbox.getText());
// rtf=rtemp.doubleValue();

if (input > 40)
{
hours = (input - 40);


pay = input2 * hours/2;
total = input2 * hours + pay;
outp.setText("pay is " + total);
}
else if (input <= 40)
{
total = input * input2;

outp.setText("pay is " + total);
}
}

}






I need to develop a Java applet or if you wish a JAVA application that will determine the gross pay for each of several employees. The company pays "straight-time" for the first 40 hours worked by each employee and pays "time and one half" for all hours worked in excess of 40 hours. Your program should input the information and display the employee's gross pay. Use TextFields to input the data. Use integers for input and a double for the output.


Cant figure it out?

currently get 7 errors?

Comments

  • You need to declare a variable before you try to use it
    [code]
    try {
    double hoursWorked = new Double(this.input.getText()).doubleValue();
    double rate = new Double(this.input2.getText()).doubleValue();

    if (hoursWorked > 40) {
    double hours = (hoursWorked - 40);

    double pay = rate * hours / 2;
    double total = rate * hours + pay;
    outp.setText("pay is " + total);
    } else if (hoursWorked <= 40) {
    double total = hoursWorked * rate;

    outp.setText("pay is " + total);
    }
    } catch (NumberFormatException ex) {
    outp.setText("invalid input");
    }
    [/code]

    Use ActionListeners with button controls like so:
    [code]
    button = new Button("ENTER");
    button.addActionListener(this);
    [/code]

    ---------------------------------
    [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion