Skip to content
Open

lab2 #71

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
4 changes: 4 additions & 0 deletions src/main/java/kz/edu/nu/cs/exercise/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ public abstract class State {
protected StateContext sc;
protected boolean accept = false;

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

public void actionA() {
}

Expand Down
17 changes: 17 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,17 @@
package kz.edu.nu.cs.exercise;

public class State1 extends State {
public State1(StateContext StateContext) {
super(StateContext);
this.accept = false;
}
@Override
public void actionA() {
this.sc.setCurrentState(this.sc.state2);

}
@Override
public void actionB() {
this.sc.setCurrentState(this.sc.state2);
}
}
17 changes: 17 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,17 @@
package kz.edu.nu.cs.exercise;

public class State2 extends State {
public State2(StateContext StateContext) {
super(StateContext);
this.accept = false;
}
@Override
public void actionA() {
this.sc.setCurrentState(this.sc.state3);
}
@Override
public void actionB() {
this.sc.setCurrentState(sc.state1);
}
}

16 changes: 16 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,16 @@
package kz.edu.nu.cs.exercise;

public class State3 extends State {
public State3(StateContext StateContext) {
super(StateContext);
this.accept = true;
}
@Override
public void actionA() {
this.sc.setCurrentState(this.sc.state3);
}
@Override
public void actionB() {
this.sc.setCurrentState(this.sc.state2);
}
}
5 changes: 4 additions & 1 deletion src/main/java/kz/edu/nu/cs/exercise/StateContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ public StateContext() {
public void actionA() {
// complete this method by
// delegation to the current state
this.getCurrentState().actionA();
}

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

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

}

public State getCurrentState() {
Expand Down