• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

no error messages but program doesn't display required results

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
kanaka tam
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ask yourself "Where does the variable 'hours' get set to equal the number of hours entered into the text field?"
 
kanaka tam
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Watchya got in that poodle gun? Anything for me? Or this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic