Skip to content

Instantly share code, notes, and snippets.

@ocus
Last active August 29, 2015 14:23
Show Gist options
  • Save ocus/8d2c99b35c1168b57977 to your computer and use it in GitHub Desktop.
Save ocus/8d2c99b35c1168b57977 to your computer and use it in GitHub Desktop.

Revisions

  1. ocus revised this gist Jun 17, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # The light show !

    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 or off at will.
    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:

  2. ocus created this gist Jun 17, 2015.
    38 changes: 38 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    # The light show !

    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 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*.

    ## Tasks
    - Write the code for the classes `LightBulb` and `ControlPanel` 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 the `ControlPanel` class***.
    - Identify and explain the conception/coding errors induced by the fact of not having thought of all kinds of bulbs from the start.