diff --git a/src/main/java/kz/edu/nu/cs/exercise/StateContext.java b/src/main/java/kz/edu/nu/cs/exercise/StateContext.java index 3b154c4..a03cfd8 100644 --- a/src/main/java/kz/edu/nu/cs/exercise/StateContext.java +++ b/src/main/java/kz/edu/nu/cs/exercise/StateContext.java @@ -1,5 +1,6 @@ package kz.edu.nu.cs.exercise; + public class StateContext { final State state1 = new State1(this); final State state2 = new State2(this); @@ -12,19 +13,35 @@ public StateContext() { } public void actionA() { + if (this.currentState == state1) + this.currentState = state2; + else if (this.currentState == state2) + this.currentState = state3; + else if (this.currentState == state3) + this.currentState = state3; // complete this method by // delegation to the current state } public void actionB() { + if (this.currentState == state2) + this.currentState = state1; + else if (this.currentState == state3) + this.currentState = state2; + else if (this.currentState == state1) + this.currentState = state1; // complete this method // delegate to the current state } public boolean inAcceptState() { + if (this.currentState == state3){ + return true; + }else { // complete this method and return correct value // delegate to the current state return false; + } } public State getCurrentState() { @@ -35,4 +52,24 @@ public void setCurrentState(State currentState) { this.currentState = currentState; } + private static class State1 extends State { + + public State1(StateContext aThis) { + } + } + + private static class State2 extends State { + + public State2(StateContext aThis) { + } + } + + private static class State3 extends State { + + public State3(StateContext aThis) { + } + } + + + }