# Unit 3 – Advanced Demo: Temperature Sensor

Extends the basic temperature sensor demo. The sensor still records 
readings and tracks the min/max range, but now it classifies each reading 
into a named category and raises an alert if the temperature goes outside 
a safe range — using `when` and `if` as expressions that produce values 
rather than statements that print them.

## Setting up

1. Compile `TemperatureSensor`.
2. Create a sensor: `TemperatureSensor("Greenhouse")`.
3. Call `report()` — the default reading is 20.0°C, categorised as 
   Comfortable.

## Experimenting

4. Call `measure(-5.0)` — watch the message in the terminal. Call 
   `report()` — both the category and the alert reflect the new reading.
5. Call `measure(12.0)` — the category changes and the alert clears.
6. Call `measure(40.0)` — the sensor is now Hot and the alert fires again.
7. After several readings, call `rangeReport()` — it shows the lowest and 
   highest values recorded across all calls to `measure()`.
8. Create a second sensor: `TemperatureSensor("Freezer")`. Take different 
   readings on each and call `rangeReport()` on both — each sensor tracks 
   its own range independently.

## What to look at in the code

9. Open TemperatureSensor and find `category()`. The `when` here has no 
   value after the keyword — each branch tests its own full condition. 
   Unlike `printCategory()` in the basic demo, this `when` is used as 
   an expression: the whole construct produces a `String` value that is 
   returned.
10. Find `alert()`. The `if/else` here is also used as an expression — 
    it produces a `String` and is returned directly. Compare this with 
    the `if` statements in `measure()`, which update properties and 
    return nothing.
11. Find `report()`. It calls `category()` and `alert()` inside a String 
    template — both return values, so they can be embedded directly into 
    the result string.
