← Unit 3 · all exercises
Saved in this browser only

How far through the book

Write a Reader holding a total page count and the pages read so far, starting at 0. read adds pages but never past the total. percent returns the percentage read, rounded down to a whole number.

class Reader { Reader(int totalPages); void read(int pages); int percent(); }

Reader.java
Loading editor…
Results

Examples

  • Reader r = new Reader(200); r.read(50); r.percent() → 25
  • Reader r = new Reader(200); r.read(500); r.percent() → 100cannot exceed the book

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