// COM1204 Quiz2 B code "The Dog Sam", 8/2003

public abstract class DogState {
        String status;
    
    abstract DogState command();
    
    void showStatus() {
        System.out.println("Dog is: " + status);
    }
}

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

public class DogSit extends DogState {
    
    DogSit() {
        status = "Sitting";
    }
    
    DogState command(){
        return  AllDogStates.STAND;
        }
}

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

public interface AllDogStates {
    
    public static final DogState LIE = new DogLie();
    public static final DogState SIT = new DogSit();
    public static final DogState STAND = new DogStand();
    
}
    
// ****************************************************

public  class Dog {
    
    DogState state;
    
    Dog() {
        state = AllDogStates.LIE;
        state.showStatus();
    }
    
    void command(){
    state = state.command();
    state.showStatus();
    }
}

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

public class DogTest {
    
    public static void main(String[] args) {
        
        Dog dog = new Dog();
        dog.command();
        dog.command();
        dog.command();
        dog.command();
        dog.command();
        dog.command();
    }
}

/* Output of above is:
Dog is: Lying down
Dog is: Sitting
Dog is: Standing
Dog is: Lying down
Dog is: Sitting
Dog is: Standing
Dog is: Lying down
*/

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

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

public class DogLie extends DogState {
    
    DogLie() {
        status = "Lying down";
    }
    
    DogState command(){
        return AllDogStates.SIT;
        }
}

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


public class DogStand extends DogState {
    
    DogStand() {
        status = "Standing";
    }
    
    DogState command(){
        return AllDogStates.LIE;
        }
}