Exercise: Adapter
This exercise puts the Adapter pattern into code.
Scenario
A heating system expects a thermostat that reports temperature in Fahrenheit. The only sensor
available is a CelsiusSensor that exposes a celsius() method returning an integer. Your
task is to write a CelsiusToFahrenheitAdapter that implements a FahrenheitThermometer
interface, so the driver calls fahrenheit() without ever knowing a Celsius sensor is underneath.
Commands
| Command | Behavior | Output |
|---|---|---|
["reading", celsius] | Set the sensor to celsius and return the Fahrenheit equivalent | "<f>F" |
The conversion formula uses integer division: f = c * 9 // 5 + 32. The result is always a whole
number — a reading of 37°C gives 98F, not 98.6°F.
5 reading 0 reading 100 reading -40 reading 20 reading 37
32F 212F -40F 68F 98F
Your task
Implement the skeleton in the editor below so the commands produce the output described above.