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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}
4 changes: 4 additions & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target/
.settings/
.classpath
.project
1 change: 1 addition & 0 deletions bin/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: java
40 changes: 40 additions & 0 deletions bin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>kz.edu.nu.cs</groupId>
<artifactId>stateexercise-361</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>stateexercise-361</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
26 changes: 26 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,26 @@
package kz.edu.nu.cs.exercise;

public class State1 extends State {

public State1(StateContext stateContext) {
// TODO Auto-generated constructor stub
this.sc = stateContext;
}

public void actionA() {

this.sc.setCurrentState(sc.state2);
}

public void actionB() {

this.sc.setCurrentState(sc.state1);

}

public boolean inAcceptState() {

return false;
}

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

public class State2 extends State {

public State2(StateContext stateContext) {
// TODO Auto-generated constructor stub
this.sc = stateContext;
}

public void actionA() {

this.sc.setCurrentState(sc.state3);
}

public void actionB() {

this.sc.setCurrentState(sc.state1);

}

public boolean inAcceptState() {

return false;
}

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

public class State3 extends State {

public State3(StateContext stateContext) {
// TODO Auto-generated constructor stub
this.sc = stateContext;
}

public void actionA() {

this.sc.setCurrentState(sc.state3);
}

public void actionB() {

this.sc.setCurrentState(sc.state2);

}

public boolean inAcceptState() {

return true;
}

}
71 changes: 38 additions & 33 deletions src/main/java/kz/edu/nu/cs/exercise/StateContext.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
package kz.edu.nu.cs.exercise;

public class StateContext {
final State state1 = new State1(this);
final State state2 = new State2(this);
final State state3 = new State3(this);

private State currentState;

public StateContext() {
this.currentState = state1;
}

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

public void 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;
}

public State getCurrentState() {
return currentState;
}

public void setCurrentState(State currentState) {
this.currentState = currentState;
}
final State state1 = new State1(this);
final State state2 = new State2(this);
final State state3 = new State3(this);

private State currentState;

public StateContext() {
this.currentState = state1;
}

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

}

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

}

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

public State getCurrentState() {
return currentState;
}

public void setCurrentState(State currentState) {
this.currentState = currentState;
}

}