diff --git a/src/main/java/kz/edu/nu/cs/exercise/State1.java b/src/main/java/kz/edu/nu/cs/exercise/State1.java new file mode 100644 index 0000000..93e645d --- /dev/null +++ b/src/main/java/kz/edu/nu/cs/exercise/State1.java @@ -0,0 +1,27 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package kz.edu.nu.cs.exercise; + +/** + * + * @author Abylay + */ +public class State1 extends State { + + public State1(StateContext sc) { + this.sc = sc; + accept = false; + } + + public void actionA() { + sc.setCurrentState(sc.state2); + } + + public void actionB() { + sc.setCurrentState(sc.state1); + } + +} diff --git a/src/main/java/kz/edu/nu/cs/exercise/State2.java b/src/main/java/kz/edu/nu/cs/exercise/State2.java new file mode 100644 index 0000000..3907edd --- /dev/null +++ b/src/main/java/kz/edu/nu/cs/exercise/State2.java @@ -0,0 +1,28 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package kz.edu.nu.cs.exercise; + +/** + * + * @author Abylay + */ +public class State2 extends State { + StateContext stateContext; + + public State2(StateContext sc) { + this.sc = sc; + accept = false; + } + + public void actionA() { + sc.setCurrentState(sc.state3); + } + + @Override + public void actionB() { + sc.setCurrentState(sc.state1); + } +} diff --git a/src/main/java/kz/edu/nu/cs/exercise/State3.java b/src/main/java/kz/edu/nu/cs/exercise/State3.java new file mode 100644 index 0000000..402ad12 --- /dev/null +++ b/src/main/java/kz/edu/nu/cs/exercise/State3.java @@ -0,0 +1,27 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package kz.edu.nu.cs.exercise; + +/** + * + * @author Abylay + */ +public class State3 extends State { + StateContext stateContext; + + public State3(StateContext sc) { + this.sc = sc; + accept = true; + } + + public void actionA() { + sc.setCurrentState(sc.state3); + } + + public void actionB() { + sc.setCurrentState(sc.state2); + } +} 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..5fbb700 100644 --- a/src/main/java/kz/edu/nu/cs/exercise/StateContext.java +++ b/src/main/java/kz/edu/nu/cs/exercise/StateContext.java @@ -9,22 +9,26 @@ public class StateContext { public StateContext() { this.currentState = state1; + } public void actionA() { // complete this method by // delegation to the current state + getCurrentState().actionA(); } public void actionB() { // complete this method // delegate to the current state + getCurrentState().actionB(); } public boolean inAcceptState() { // complete this method and return correct value // delegate to the current state - return false; + boolean acc = getCurrentState().isAccept(); + return acc; } public State getCurrentState() {