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
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

448 changes: 448 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

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

public class State1 extends State {

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

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

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

@Override
public boolean isAccept() {
return false;
}
}
22 changes: 22 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,22 @@
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(sc.state3);
}

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

@Override
public boolean isAccept() {
return false;
}
}
24 changes: 24 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,24 @@
package kz.edu.nu.cs.exercise;

public class State3 extends State {

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

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

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

}

@Override
public boolean isAccept() {
return true;
}
}
9 changes: 8 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,24 @@ 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;
if(this.currentState == state3) {
return true;
} else {
return false;
}

}

public State getCurrentState() {
Expand Down
11 changes: 11 additions & 0 deletions src/main/main.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
6 changes: 3 additions & 3 deletions src/test/java/kz/edu/nu/cs/exercise/TestStatePattern.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package kz.edu.nu.cs.exercise;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class TestStatePattern {

StateContext sc;
Expand Down
11 changes: 11 additions & 0 deletions src/test/test.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>