CJCoding With Joseph
15free / daySign inCreate account

Two interfaces are provided. Switchable describes something that turns on and off, and Dimmable describes something with a brightness level. Write the class SmartLight so that it implements both.

Requirements: 1. The class header declares that SmartLight implements Switchable and Dimmable. 2. A new light is off and its level is 100. There is no constructor to write. 3. toggle() switches the light on when it is off, and off when it is on. isOn() reports the current state. 4. setLevel(int percent) stores the new level. A value below 0 is stored as 0 and a value above 100 is stored as 100. 5. getLevel() returns the stored level. Turning the light off does not change the level. 6. Do not change the two interfaces.

The tests hold one SmartLight in a Switchable variable and in a Dimmable variable.

Do NOT write a main method.

Expected output

false
100
true
40
false
40

= newline. The output ends with a newline, so print one after the last line.

Hints4 available
Topics
InterfacesClasses
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.