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



public void actionA() {
}

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

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

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

}

@Override
public void actionB() {
}

}
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 sc) {
this.sc = sc;
}
@Override
public void actionA() {
this.sc.setCurrentState( this.sc.state3);
}

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

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

public class State3 extends State {
public State3(StateContext sc) {
this.sc = sc;
accept = true;
}


@Override
public void actionA() {
}

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

}
4 changes: 3 additions & 1 deletion src/main/java/kz/edu/nu/cs/exercise/StateContext.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ 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
getCurrentState().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
Empty file modified src/test/java/kz/edu/nu/cs/exercise/TestStatePattern.java
100644 → 100755
Empty file.
16 changes: 16 additions & 0 deletions stateexercise-361.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>