FunctionRacerProblemsRace

Odometer With a Trip Meter

BeginnerClassesPython, JavaScript, TypeScript, Java, C++

Implement a class Odometer for the distance display of a car. It shows a total that rolls over like a five-digit counter, and a trip distance that the driver can reset. Write these methods:

The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.

Example 1

Odometer(99950)
drive(30) returns 99980
drive(40) returns 20
read_trip() returns 70
reset_trip() returns 70
drive(5) returns 25
read_trip() returns 5
read_total() returns 25

The second drive takes the total past 99999, so it rolls over to 20. The trip keeps counting up to 70 until it is reset.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Classes problems