The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Re: help with clock class

Well the incrementing shouldn't be too bad.

If you incremented by n seconds, then as long as n >= 60, increment by minutes instead and subtract 60 from n. When 0 <= n < 60, add that to the current number of seconds. If the result is >= 60, subtract 60 and increment minutes again.

Ditto for minutes & hours.

For hours, just subtract 24 from n until 0 <= n < 24, and then add that to hours. If the result >= 24, subtract 24.

There are more efficient ways to do this involving integer division and modulus operators, but loops are easy and none of this is going to be expensive.