You are given the task to create the Java classes corresponding to light bulbs (of different characteristics) that can be individually plugged-in on one of the 4 sockets of a control panel allowing the light on or off at will.
The produced code must allow executing the "script" as follows:
static public void main(String[] args) {
// Technicians are working hard to mount this...
LightBulb a1 = new LightBulb("yellow");
LightBulb a3 = new LightBulb("red");
ControlPanel pdc = new ControlPanel();
pdc.display();
pdc.plugInLightBulb(a1, 1);
pdc.plugInLightBulb(a3, 3);
pdc.display();
// The mad lighting designer starts his show !
for (int i = 0; i < 10; i++) {
System.out.println("Loop: " + i);
pdc.display();
pdc.turnOnLightBulb(1);
pdc.turnOnLightBulb(2);
pdc.display();
pdc.turnOffLightBulb(1);
pdc.turnOffLightBulb(2);
}
// The show was crazy !
}
We will make sure that the light bulbs burn-out after they were lit 7 times.
- Write the code for the classes
LightBulb
andControlPanel
in Java. - Write a class
EternalLightBulb
for light bulbs that never burn-out. Use this new light bulb type with the panel. You cannot modify theControlPanel
class. - Identify and explain the conception/coding errors induced by the fact of not having thought of all kinds of bulbs from the start.