No error messages but doesn't give the required output..



Hello folks,
I wrote the program below to calculate cost of phone call when the user
enters values for hours, minutes and seconds. I have to convert hours and
seconds to minutes so that i can calculate cost of phone call which is 10
cents per min. Code compiles without any errors but does not display the
output. Listed below is the code. I would greatly appreciate any help.
Thanx,
kt

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

public class Lab8a extends Applet
implements ActionListener
{
private TextField hourTF, minTF, secTF, outputTF;
private Button calculateButton, clearButton;
private int hours, mins, secs, totalMin, totalCost;

public void init()
{
Label inputLbl, hrLbl, minLbl, secLbl, outputLbl;
inputLbl = new Label("Please enter an integer value only");
outputLbl = new Label("The cost of phone call in cents:");

hrLbl = new Label("Hours:");
minLbl = new Label("Minutes:");
secLbl = new Label("Seconds:");

hourTF = new TextField(7);
minTF = new TextField(7);
secTF = new TextField(7);
outputTF = new TextField(7);

calculateButton = new Button("CALCULATE");
clearButton = new Button("CLEAR");

add(inputLbl);
add(hrLbl);
add(hourTF);
add(minLbl);
add(minTF);
add(secLbl);
add(secTF);
add(calculateButton);
add(clearButton);
add(outputLbl);
add(outputTF);

hourTF.addActionListener(this);
minTF.addActionListener(this);
secTF.addActionListener(this);
outputTF.addActionListener(this);
clearButton.addActionListener(this);
calculateButton.addActionListener(this);

}

public void actionPerformed (ActionEvent event)
{
outputTF.setEditable(false);

if(event.getSource() == calculateButton)
{
calculateTotal();
outputTF.setText(Integer.toString(totalCost));
}

if(event.getSource() == clearButton)
outputTF.setText("");


}

public int calculateTotal()
{
totalMin = hours * 60 + mins + secs / 60;
totalCost = totalMin * 10;
return totalCost;
}

public void paint(Graphics g)
{


}

}

--
Message posted via http://www.javakb.com
.



Relevant Pages