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 {

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

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

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

public boolean inAcceptState() {

return this.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 {

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

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

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

public boolean inAcceptState() {

return this.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 {

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

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

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

public boolean inAcceptState() {

return this.accept;
}

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

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

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

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

return currentState.isAccept();
}

public State getCurrentState() {
Expand Down