← Unit 3 · all exercises
Saved in this browser only

A countdown timer

Write a Timer holding a number of seconds. tick takes one second off, but never below zero. isFinished returns true when it has reached zero, and getSeconds returns the value.

class Timer { Timer(int seconds); void tick(); boolean isFinished(); int getSeconds(); }

Timer.java
Loading editor…
Results

Examples

  • Timer t = new Timer(3); t.tick(); t.getSeconds() → 2
  • new Timer(0).isFinished() → true

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