Skip to content
Open

done #79

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/main/java/kz/edu/nu/cs/exercise/StateContext.java
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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() {
Expand All @@ -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) {
}
}



}