aspose file tools*
The moose likes Beginning Java and the fly likes no error messages but program doesn't display required results Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "no error messages but program doesn Watch "no error messages but program doesn New topic
Author

no error messages but program doesn't display required results

kanaka tam
Ranch Hand

Joined: Jan 19, 2004
Posts: 42
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. I would greatly appreciate any help.
Thanx,
kanaka
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

You're assuming that paint() will be called after each textfield is changed, or before the "calculate" handler runs. There's no reason to believe that.

Move the contents of "paint()" into a "calculate" method, and then call calculate() in the event handler, before using the variable totalValue.


[Jess in Action][AskingGoodQuestions]
kanaka tam
Ranch Hand

Joined: Jan 19, 2004
Posts: 42
Originally posted by Ernest Friedman-Hill:
You're assuming that paint() will be called after each textfield is changed, or before the "calculate" handler runs. There's no reason to believe that.

Move the contents of "paint()" into a "calculate" method, and then call calculate() in the event handler, before using the variable totalValue.

Ernest,
Thank you for replying. This is the change i did to the code. I think i understood what you meant. But still not getting the output.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Ask yourself "Where does the variable 'hours' get set to equal the number of hours entered into the text field?"
kanaka tam
Ranch Hand

Joined: Jan 19, 2004
Posts: 42
Ernest,
Thank you sooooo much. I figured what silly mistake i was doing. I am a beginner striving to do good programming. I got the output now. This is the code i had to add to fix the problem.

public int calculateTotal()
{
hours = Integer.parseInt(hourTF.getText());
mins = Integer.parseInt(minTF.getText());
secs = Integer.parseInt(secTF.getText());

totalMin = hours * 60 + mins + secs / 60;
totalCost = totalMin * 10;
return totalCost;
}
Thank again,
Kanaka
kanaka tam
Ranch Hand

Joined: Jan 19, 2004
Posts: 42
Originally posted by Ernest Friedman-Hill:
Ask yourself "Where does the variable 'hours' get set to equal the number of hours entered into the text field?"


Ernest,
Thank you sooooo much. I figured what silly mistake i was doing. I am a beginner striving to do good programming. I got the output now. This is the code i had to add to fix the problem.

public int calculateTotal()
{
hours = Integer.parseInt(hourTF.getText());
mins = Integer.parseInt(minTF.getText());
secs = Integer.parseInt(secTF.getText());

totalMin = hours * 60 + mins + secs / 60;
totalCost = totalMin * 10;
return totalCost;
}
Thank again,
Kanaka
 
Consider Paul's rocket mass heater.
 
subject: no error messages but program doesn't display required results