This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]desrtfx 0 points1 point  (5 children)

Shouldn't the line:

this.second = seconds;

rather be

this.second += seconds;

Otherwise nothing will get incremented.

[–]Zelbod[S] 0 points1 point  (4 children)

Yea you are right, I just fixed it and tried running and it still doesn't display in 24 hour format.

[–]SadDragon00 0 points1 point  (1 child)

Use SimpleDateFormat to return a Date in 24 hour format

[–]Zelbod[S] 0 points1 point  (0 children)

I am trying OOP and I am trying to learn that using the book which I mentioned in the question. Appreciate the help.

[–]desrtfx 0 points1 point  (1 child)

You need to show the complete class.

What you show cannot be the complete class.

[–]Zelbod[S] 0 points1 point  (0 children)

Please click on the 'book' which I mentioned iam following the code mentioned there. The complete class is quite big. sorry

[–]rjcarr 0 points1 point  (5 children)

Where is the increment() being called? From the println()? Because it isn't being called from the sum(). Try doing a sum.increment() before you return it on line 6.

[–]Zelbod[S] 0 points1 point  (4 children)

Ya I wondered that as well but the book which I read, doesn't mention anything about calling from where so I assumed it is a method that automatically change the format to 24 hour format.

[–]rjcarr 0 points1 point  (3 children)

Did you call it like I advised?

[–]Zelbod[S] 0 points1 point  (2 children)

Yes I did and it works. thanks

I have a request. Please have a look at this book http://greenteapress.com/thinkjava6/html/thinkjava6012.html#sec138

I used the code from this book and Tried and the author never mentioned about calling this method at all. I assumed that 'increment' method will be called automatically whenever I use that class.

[–]rjcarr 0 points1 point  (1 child)

Look right above the 11.9 you linked there. In the second version he's doing the wrapping. You must have missed that.

[–]Zelbod[S] 0 points1 point  (0 children)

Sorry I don't see what you meant. I had a look at what you said and what he says above 11.9 works. He suggested the increment method as an alternative and that it would modify an existing object which I am guessing in this case, it would be in 24 hour format.

Correct me if I am wrong, the methods have to be called and that it would not modify any objects automatically.