Preparing your design workspace

Loading the problem and your saved attempt…

Model Room Appliances with OOP

Model and implement power and settings for a room’s lamp and fan while demonstrating all four OOP pillars.

For this exercise, assume one room initially contains a lamp and a fan. A user can turn an individual appliance on or off, read its power and setting, and apply one power command to every appliance in the room. The lamp accepts integer brightness from 0 through 100; the fan accepts integer speed from 1 through 3.

Both start powered off, with lamp brightness 50 and fan speed 1. Valid settings may change while an appliance is off and persist across power changes. An invalid setting is rejected without changing any observable state.

Design the objects, contracts and interactions, then implement the bounded in-memory core and identify how its code demonstrates encapsulation, abstraction, inheritance and polymorphism. The caller supplies Boolean power commands and integer setting values.

Select a coherent object model rather than merely listing pillar definitions.

For this exercise, assume hardware failures, network communication, persistence, concurrent callers, device discovery and graphical interfaces are outside scope. For the follow-up, add a heater whose integer setting is a temperature from 18 through 30, initially 20, with the same power and invalid-update rules.

Explain how existing room callers continue working and how you would test the addition.