You are required to build a Smart Home Device Management System.
The system must support multiple types of devices and allow a home to manage them.
This challenge is designed to test your understanding of:
Encapsulation Inheritance Polymorphism Composition Unit Testing (JUnit) 🚨 Rules Do NOT modify the test file Your solution must compile and pass all tests Follow clean OOP principles No hardcoding to satisfy tests 📁 Project Structure src/
└── main/java/
└── za/co/wethinkcode/smarthome/
Device.java
Light.java
Thermostat.java
SmartHome.java
src/
└── test/java/
└── za/co/wethinkcode/smarthome/
SmartHomeTest.java
🧩 Requirements
- Device (Encapsulation)
Create a class Device with:
Fields
String name
boolean isOn
Methods
void turnOn()
void turnOff()
String getStatus()
Expected Behavior
Devices are OFF by default
getStatus() returns:
is ON
or
is OFF
- Light
Create class Light that extends Device.
Fields
String name
int brightness
Methods
Rules
Default brightness = 0
getStatus() must return:
Light is ON at brightness
- Thermostat
Create class Thermostat that extends Device.
Fields
double temperature
Methods
Constructor: Thermostat(String name)
void setTemperature(double temperature)
double getTemperature()
Rules
Default temperature = 20.0
getStatus() must return:
Thermostat is ON at °C
- SmartHome (Composition)
Create class SmartHome.
Fields
A collection of Device objects
Methods
void addDevice(Device device)
List getDevices()
String getAllStatuses() Expected Behavior
getAllStatuses() returns all device statuses separated by newline (\n)
No trailing newline