JavaNovice484
Programmer
Greetings,
I'm trying to create a simple applet...I'm have problems getting my application to perform the correct calculations any assistance would be greatly appreciated.
I'm trying to get the cost per Kilowatt-hour in cents * the kilowatt-hours consumed.
I'm trying to create a simple applet...I'm have problems getting my application to perform the correct calculations any assistance would be greatly appreciated.
I'm trying to get the cost per Kilowatt-hour in cents * the kilowatt-hours consumed.
Code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class KilowattApplet extends Applet implements ActionListener
{
//Declare Varaibles
int cents,hours;
//Construct Components
Label welcome = new Label("Welcome to the Appliance Energry Calculator");
Label costKwhrLabel = new Label("Please enter the cost per kilowatt-hour in cents:");
TextField costKwhrField = new TextField(5);
Label hoursPerYearLabel = new Label("Please enter the kilowatt-hours consumed:");
TextField hoursPerYearField = new TextField(5);
Button calcButton = new Button("Calculate");
Label outputLabel = new Label("Click the Calculate button to display the average energy cost.");
public void init()
{
setForeground(Color.magenta);
setBackground(Color.darkGray);
add(welcome);
add(costKwhrLabel);
add(costKwhrField);
add(hoursPerYearLabel);
add(hoursPerYearField);
add(calcButton);
calcButton.addActionListener(this);
add(outputLabel);
}
public void actionPerformed(ActionEvent e)
{
//Declare Varaibles
int average;
double costKwhr = Double.parseDouble(costKwhrField.getText());
double cosumedKwhr = Double.parseDouble(hoursPerYearField.getText());
costKwhr = cents;
cosumedKwhr = hours
average = cents * hours;
outputLabel.setText("The average annual cost to operate this appliance is $" +Math.round(average* 100)/100D);
}
}