Home automation
Create a system that consists of 3 classes: Lamp, DimmableLamp and PhilipsHUELamp:
- A Lamp can be turned on and off and you can query whether the lamp is on or off. The default state of the lamp is off.
- A DimmableLamp can do everything a Lamp can, but also has an adjustable brightness (0% to 100%). Default brightness is 100%.
- A PhilipsHUELamp can do everything a DimmableLamp can do (and therefore also what a Lamp can do), but also has a certain light color that you can adjust. By default, the color is white.
Implementation of the classes
Write the above classes, where:
- Classes have multiple constructors (so you can set the brightness and color right away when creating).
- Use the
java.awt.Color
class as type for your color attribute.
- Each class has a proper and unique
toString()
method to describe the state of the light. Hint: make use of the toString()
of your superclass.
Examples
The first output is generated by:
- A regular lamp, switched on.
- A dimmable lamp, at 50% brightness which is also turned on.
- A Philips HUE lamp with the color “green” (note the RBG value), with 100% brightness, but isn’t turned on.
Regular Lamp
Status: ON
Dimmable lamp:
Brightness: 50%, Status: ON
Philips HUE lamp:
Color: java.awt.Color[r=0,g=255,b=0], Brightness: 100%, Status: OFF
The second output shows the same lamps, but with some adjusted settings:
- This lamp has been turned off.
- This lamp now has a reduced brightness of 50%.
- This lamp has been turned on, it’s brightness reduced to 70% and the color was set to “blue”.
Regular Lamp
Status: OFF
Dimmable lamp:
Brightness: 10%, Status: ON
Philips HUE lamp:
Color: java.awt.Color[r=0,g=0,b=255], Brightness: 70%, Status: ON
Testing
In order to test the application, the code from TestApplication
can be used. This file can be downloaded here. Make sure that you copy the file to the appropiate location in your project. Make sure all scenarios pass their tests.
Relevant links