• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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: 24204
44
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: 24204
44
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
 
What is that? Is that a mongol hoarde? Can we fend them off with this tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic