// COM1204 Quiz2 A code "Lamp", 8/2003

public abstract class LampState {
        String status;
    
    abstract LampState click();
    
    void showStatus() {
        System.out.println("Lamp state is: " + status);
    }
}

// ****************************************************

public class LampDim extends LampState {
    
    LampDim() {
        status = "Dim";
    }
    
    LampState click(){
        return  AllLampStates.BRIGHT;}
}

// ****************************************************

public interface AllLampStates {
    
    public static final LampState OFF = new LampOff();
    public static final LampState DIM = new LampDim();
    public static final LampState BRIGHT = new LampBright();
    
}
    
// ****************************************************

public  class Lamp {
    
    LampState state;
    
    Lamp() {
        state = AllLampStates.OFF;
        state.showStatus();
    }
    
    void click(){
    state = state.click();
    state.showStatus();
    }
}

// ****************************************************

public class LampTest {
    
    public static void main(String[] args) {
        
        Lamp lamp = new Lamp();
        lamp.click();
        lamp.click();
        lamp.click();
        lamp.click();
        lamp.click();
        lamp.click();
    }
}

/* Output of LampTest is:
Lamp state is: Off
Lamp state is: Dim
Lamp state is: Bright
Lamp state is: Off
Lamp state is: Dim
Lamp state is: Bright
Lamp state is: Off
*/

// ****************************************************

/* The following two classes are necessary to compile and run the code,
 * but you were not asked to write them.
 */

public class LampBright extends LampState {
    
    LampBright() {
        status = "Bright";
    }
    
    LampState click(){
        return AllLampStates.OFF;}
    
}

// ****************************************************

public class LampOff extends LampState {
    
    LampOff() {
        status = "Off";
    }
    
    LampState click(){
        return AllLampStates.DIM;}
}