Design and refactor a ClimateConsole that manages room temperatures.
Every room starts at 20C and owns a thermostat whose valid range is 16 through 30C. A room may be occupied or empty. Empty rooms refuse temperature changes before the thermostat is consulted.
The console supports:
addRoom(name, occupied), which returns the new room id;setOccupied(roomId, occupied), which returns false for an unknown room;requestTemperature(roomId, temperature), which returns "UNKNOWN", "EMPTY_ROOM", "OUT_OF_RANGE", or "SET";temperature(roomId), which returns -1 for an unknown room;status(roomId), which returns "<name>: <temperature>C, OCCUPIED" or "<name>: <temperature>C, EMPTY", and "UNKNOWN" for an invalid id; androomCount().
The legacy console retrieves a room's thermostat and talks to it directly. That shortcut bypasses the room's occupancy rule. Refactor the code so the console knows rooms, rooms know thermostats, and each layer exposes the operation its caller actually needs.
Example 1:
Input:
Output:
Explanation: The room enforces occupancy. The thermostat handles only its own temperature range and stored value.
Example 2:
Input:
Output:
Constraints
1 <= name.length <= 40-100 <= temperature <= 100- At most
100 calls will be made across all methods.
Starter Code
The starter compiles, but the console reaches through each room to its thermostat and can change an empty room.