← Unit 3 · all exercises
Saved in this browser only

A clock that wraps around

Write a Clock holding hours and minutes. tick adds one minute; at 60 minutes the hour goes up and the minutes go back to 0, and after 23 the hour wraps to 0. show returns the time as "HH:MM" with two digits each.

class Clock { Clock(int h, int m); void tick(); String show(); }

Clock.java
Loading editor…
Results

Examples

  • new Clock(9, 5).show() → 09:05
  • Clock c = new Clock(1, 59); c.tick(); c.show() → 02:00

There are also 3 hidden tests you can't see. Solve the problem, not the examples.