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
27 changes: 27 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,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);
}

}
28 changes: 28 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,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);
}
}
27 changes: 27 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,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);
}
}
6 changes: 5 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 @@ -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() {
Expand Down