← Unit 3 · all exercises
Saved in this browser only

Keeping score

Write a ScoreKeeper that starts at 0. add increases the score by the amount given, reset puts it back to 0, and getScore returns it.

class ScoreKeeper { ScoreKeeper(); void add(int points); void reset(); int getScore(); }

ScoreKeeper.java
Loading editor…
Results

Examples

  • ScoreKeeper k = new ScoreKeeper(); k.add(10); k.add(5); k.getScore() → 15
  • ScoreKeeper k = new ScoreKeeper(); k.add(10); k.reset(); k.getScore() → 0

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