View Single Post
Join Date: Dec 2007
Posts: 1,525
Reputation: javaAddict is a glorious beacon of light javaAddict is a glorious beacon of light javaAddict is a glorious beacon of light javaAddict is a glorious beacon of light javaAddict is a glorious beacon of light javaAddict is a glorious beacon of light 
Solved Threads: 209
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: Simple Java Help

 
0
  #3
Nov 19th, 2008
Every time you do:
Time application = new Time(); you create a new object and therefor you reset the values back to zero.
So create only ONE object (do this once: Time application = new Time(); )
And then use the application instance to change its values.


By the way, the Time class is totally wrong. The get, set methods are not suppose to print anything:

  1. class Time {
  2. private int seconds = 0;
  3. ....
  4. ....
  5. public Time() {
  6.  
  7. }
  8.  
  9. public Time(int seconds, ......) {
  10. this.seconds = seconds;
  11. .....
  12. .....
  13. }
  14.  
  15. public int getSeconds() {
  16. return seconds;
  17. }
  18.  
  19. public void setSeconds(int seconds) {
  20. this.seconds = seconds;
  21. }
  22. }

Now if your teacher wants the set methods to return boolean, then:

  1. public boolean setSeconds(int seconds) {
  2. if (seconds<0) {
  3. return false;
  4. }
  5. this.seconds = seconds;
  6. return true;
  7. }
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote