FunctionRacerProblemsRace

Thermostat Between Two Limits

BeginnerClassesPython, JavaScript, TypeScript, Java, C++

Implement a class Thermostat whose target temperature always stays between low and high, both included. 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

Thermostat(18, 24)
turn_up(4) returns 22
turn_up(5) returns 24
set_target(30) returns false
set_target(20) returns true
turn_down(9) returns 18
read_target() returns 18

Turning up by 5 from 22 would pass 24, so the target stops at 24. 30 is outside the limits and is refused, 20 is accepted, and turning down by 9 stops at 18.

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