/*
   Project 2:	  In the Lab #3
   Programmer:	  Gary Haines
   Date:	  January 23, 2003
   Program Name:  KilowattApplet
*/

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class KilowattApplet extends Applet implements ActionListener
{
	Label costKwhrLabel = new Label("Please enter the cost per kilowatt-hour in cents:");
	TextField costKwhrField = new TextField(25);

	Label numHoursLabel = new Label("Please enter the number of kilowatt-hours this appliance is run:");
	TextField numHoursField = new TextField(25);

	Button calcButton = new Button("Calculate Annual Appliance Cost");

	Label outputLabel = new Label("Enter the requested data and click the button.");

	public void init()
	{
	  add(costKwhrLabel);
	  add(costKwhrField);
	  add(numHoursLabel);
	  add(numHoursField);
	  add(calcButton);
	  add(outputLabel);
	  calcButton.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e)
	{
	  //Converting input to values
	  double costKwhr = Double.parseDouble(costKwhrField.getText());
	  double numHours = Double.parseDouble(numHoursField.getText());
	
	  //Variables used in formulas and output
	  double average;
	  
	  //Calculations
	  average = costKwhr * numHours;

	  //Output
	  outputLabel.setText("The cost of running this appliance is $" + Math.round(average));
	}
}