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)
{
}
}
Thomas Fritsch - 07 Apr 2005 19:14 GMT
kt via JavaKB.com schrieb:
> Hello folks,
> I wrote the program below to calculate cost of phone call when the user
[quoted text clipped - 73 lines]
> public int calculateTotal()
> {
// Forgot to get the numbers from the TextFields into your variables:
hours = ...; // get it from hourTF
mins = ...; // get it from minTF
secs = ...; // get it from secTF
// The rest is left as an exercise to the reader ;-)
// By the way: It is not necessary to declare all these int's as member
// variables of your class. Local variables in this method would
// suffice.
> totalMin = hours * 60 + mins + secs / 60;
> totalCost = totalMin * 10;
[quoted text clipped - 8 lines]
>
> }

Signature
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
kt - 08 Apr 2005 20:12 GMT
Fritsch,
Thanx for taking your time to reply. I fixed the code.
kt