❔ Classes and objects
Hi guys, I need help solving this problem: Write a class to model a Lamp.
Provide the following methods in your class:
a) turnOn – turn ON the lamp
b) turnOff – turn OFF the lamp
c) showCurrentColor – outputs current color of lamp
Each time the lamp is turned ON, it shows a different color. The changing
color-sequence is Red, Green, Blue, then loops back to Red and so on.
The state of the lamp is initially OFF. When the lamp is turned ON for the
first time, its color should be Red.
Note that the lamp cannot be turned ON if it is already ON. Its state
needs to be OFF before a call to turnOn() has any effect.
Test that your lamp exhibits the correct color-changing order by turning
it ON and OFF 10 consecutive times.
I am stuck here, not sure how to proceed...
Provide the following methods in your class:
a) turnOn – turn ON the lamp
b) turnOff – turn OFF the lamp
c) showCurrentColor – outputs current color of lamp
Each time the lamp is turned ON, it shows a different color. The changing
color-sequence is Red, Green, Blue, then loops back to Red and so on.
The state of the lamp is initially OFF. When the lamp is turned ON for the
first time, its color should be Red.
Note that the lamp cannot be turned ON if it is already ON. Its state
needs to be OFF before a call to turnOn() has any effect.
Test that your lamp exhibits the correct color-changing order by turning
it ON and OFF 10 consecutive times.
I am stuck here, not sure how to proceed...