Skip to content
Open
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions src/main/java/kz/edu/nu/cs/exercise/State1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package kz.edu.nu.cs.exercise;

public class State1 extends State {

protected boolean accept = false;

public State1(StateContext sc) {
this.sc = sc;
}

public void actionA() {
sc.setCurrentState(sc.state2);
}

public void actionB() {
sc.setCurrentState(sc.getCurrentState());
}

public boolean isAccept() {
return accept;
}

}
23 changes: 23 additions & 0 deletions src/main/java/kz/edu/nu/cs/exercise/State2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package kz.edu.nu.cs.exercise;

public class State2 extends State{

protected boolean accept = false;

public State2(StateContext sc) {
this.sc = sc;
}

public void actionA() {
sc.setCurrentState(sc.state3);
}

public void actionB() {
sc.setCurrentState(sc.state1);
}

public boolean isAccept() {
return accept;
}

}
23 changes: 23 additions & 0 deletions src/main/java/kz/edu/nu/cs/exercise/State3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package kz.edu.nu.cs.exercise;

public class State3 extends State {

protected boolean accept = true;

public State3(StateContext sc) {
this.sc = sc;
}

public void actionA() {
sc.setCurrentState(sc.getCurrentState());
}

public void actionB() {
sc.setCurrentState(sc.state2);
}

public boolean isAccept() {
return accept;
}

}
7 changes: 5 additions & 2 deletions src/main/java/kz/edu/nu/cs/exercise/StateContext.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ public StateContext() {
}

public void actionA() {
this.currentState.actionA();
// complete this method by
// delegation to the current state
}

public void actionB() {
this.currentState.actionB();
// complete this method
// delegate to the current state
}

public boolean inAcceptState() {
// complete this method and return correct value
// delegate to the current state
return false;
return this.currentState.isAccept();
}

public State getCurrentState() {
Expand All @@ -35,4 +37,5 @@ public void setCurrentState(State currentState) {
this.currentState = currentState;
}

}

}