diff --git a/.gitignore b/.gitignore
index 520e0b1..6cf73b9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
-target/
-.settings/
-.classpath
-.project
+target/
+.settings/
+.classpath
+.project
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..aa016c3
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+stateexercise-361
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..73df473
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..2da6745
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__junit_junit_4_12.xml b/.idea/libraries/Maven__junit_junit_4_12.xml
new file mode 100644
index 0000000..d3b7192
--- /dev/null
+++ b/.idea/libraries/Maven__junit_junit_4_12.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml
new file mode 100644
index 0000000..e5d35d8
--- /dev/null
+++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..2e6579b
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..7a2d0a6
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..9661ac7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..14e543d
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,591 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ DEFINITION_ORDER
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1535080829094
+
+
+ 1535080829094
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ No facets are configured
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ stateexercise-361
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Maven: junit:junit:4.12
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index dff5f3a..a8e13e0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1 +1 @@
-language: java
+language: java
diff --git a/pom.xml b/pom.xml
index cf30781..ad594c2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,40 +1,40 @@
-
-
- 4.0.0
-
- kz.edu.nu.cs
- stateexercise-361
- 0.0.1-SNAPSHOT
- jar
-
- stateexercise-361
- http://maven.apache.org
-
-
- UTF-8
-
-
-
-
- junit
- junit
- 4.12
- test
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
- 1.8
- 1.8
-
-
-
-
-
-
+
+
+ 4.0.0
+
+ kz.edu.nu.cs
+ stateexercise-361
+ 0.0.1-SNAPSHOT
+ jar
+
+ stateexercise-361
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 1.8
+ 1.8
+
+
+
+
+
+
diff --git a/src/main/java/kz/edu/nu/cs/exercise/State.java b/src/main/java/kz/edu/nu/cs/exercise/State.java
index aa425f1..5103026 100644
--- a/src/main/java/kz/edu/nu/cs/exercise/State.java
+++ b/src/main/java/kz/edu/nu/cs/exercise/State.java
@@ -1,16 +1,21 @@
-package kz.edu.nu.cs.exercise;
-
-public abstract class State {
- protected StateContext sc;
- protected boolean accept = false;
-
- public void actionA() {
- }
-
- public void actionB() {
- }
-
- public boolean isAccept() {
- return this.accept;
- }
-}
+package kz.edu.nu.cs.exercise;
+
+public abstract class State {
+ protected StateContext sc;
+ protected boolean accept;
+
+ public State (StateContext stateContext, boolean accept){
+ this.sc = stateContext;
+ this.accept = accept;
+ }
+
+ public void actionA() {
+ }
+
+ public void actionB() {
+ }
+
+ public boolean isAccept() {
+ return this.accept;
+ }
+}
diff --git a/src/main/java/kz/edu/nu/cs/exercise/State1.java b/src/main/java/kz/edu/nu/cs/exercise/State1.java
new file mode 100644
index 0000000..2e848e8
--- /dev/null
+++ b/src/main/java/kz/edu/nu/cs/exercise/State1.java
@@ -0,0 +1,12 @@
+package kz.edu.nu.cs.exercise;
+
+public class State1 extends State {
+ public State1(StateContext stateContext, boolean accept) {
+ super(stateContext, accept);
+ }
+
+ @Override
+ public void actionA() {
+ this.sc.setCurrentState(this.sc.state2);
+ }
+}
diff --git a/src/main/java/kz/edu/nu/cs/exercise/State2.java b/src/main/java/kz/edu/nu/cs/exercise/State2.java
new file mode 100644
index 0000000..d86fb40
--- /dev/null
+++ b/src/main/java/kz/edu/nu/cs/exercise/State2.java
@@ -0,0 +1,16 @@
+package kz.edu.nu.cs.exercise;
+
+public class State2 extends State {
+ public State2(StateContext stateContext, boolean accept) {
+ super(stateContext, accept);
+ }
+ @Override
+ public void actionA() {
+ this.sc.setCurrentState(this.sc.state3);
+ }
+
+ @Override
+ public void actionB() {
+ this.sc.setCurrentState(this.sc.state1);
+ }
+}
diff --git a/src/main/java/kz/edu/nu/cs/exercise/State3.java b/src/main/java/kz/edu/nu/cs/exercise/State3.java
new file mode 100644
index 0000000..c6ecc0c
--- /dev/null
+++ b/src/main/java/kz/edu/nu/cs/exercise/State3.java
@@ -0,0 +1,12 @@
+package kz.edu.nu.cs.exercise;
+
+public class State3 extends State {
+ public State3(StateContext stateContext, boolean accept) {
+ super(stateContext, accept);
+ }
+
+ @Override
+ public void actionB() {
+ this.sc.setCurrentState(this.sc.state2);
+ }
+}
diff --git a/src/main/java/kz/edu/nu/cs/exercise/StateContext.java b/src/main/java/kz/edu/nu/cs/exercise/StateContext.java
index 3b154c4..2edc02b 100644
--- a/src/main/java/kz/edu/nu/cs/exercise/StateContext.java
+++ b/src/main/java/kz/edu/nu/cs/exercise/StateContext.java
@@ -1,38 +1,40 @@
-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;
- }
-
-}
+package kz.edu.nu.cs.exercise;
+
+public class StateContext {
+ final State state1 = new State1(this, false);
+ final State state2 = new State2(this, false);
+ final State state3 = new State3(this, true);
+
+ 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() {
+ // complete this method and return correct value
+ // delegate to the current state
+ return this.currentState.isAccept();
+ }
+
+ public State getCurrentState() {
+ return currentState;
+ }
+
+ public void setCurrentState(State currentState) {
+ this.currentState = currentState;
+ }
+
+}
diff --git a/src/test/java/kz/edu/nu/cs/exercise/TestStatePattern.java b/src/test/java/kz/edu/nu/cs/exercise/TestStatePattern.java
index 57b01eb..8696262 100644
--- a/src/test/java/kz/edu/nu/cs/exercise/TestStatePattern.java
+++ b/src/test/java/kz/edu/nu/cs/exercise/TestStatePattern.java
@@ -1,79 +1,79 @@
-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;
-
-public class TestStatePattern {
-
- StateContext sc;
-
- @Before
- public void setUp() {
- sc = new StateContext();
- }
-
- /*
- * Test Sequence: A
- */
- @Test
- public void test_1() {
- sc.actionA();
- assertFalse("Test Sequence A", sc.inAcceptState());
- }
-
- /*
- * Test Sequence: AA
- */
- @Test
- public void test_2() {
- sc.actionA();
- sc.actionA();
- assertTrue("Test Sequence AA", sc.inAcceptState());
- }
-
- /*
- * Test Sequence: A (check state)
- */
- @Test
- public void test_3() {
- sc.actionA();
- assertTrue("Test Sequence: A (check state)", sc.getCurrentState().equals(sc.state2));
- }
-
- /*
- * Test Sequence: AAB (check state)
- */
- @Test
- public void test_4() {
- sc.actionA();
- sc.actionA();
- sc.actionB();
- assertTrue("Test Sequence: AAB (check state)", sc.getCurrentState().equals(sc.state2));
- }
-
- /*
- * Test Sequence: AABB (check state)
- */
- @Test
- public void test_5() {
- sc.actionA();
- sc.actionA();
- sc.actionB();
- sc.actionB();
- assertTrue("Test Sequence: AABB (check state)", sc.getCurrentState().equals(sc.state1));
- }
-
- /*
- * Test Sequence: AAA
- */
- @Test
- public void test_6() {
- sc.actionA();
- sc.actionA();
- sc.actionA();
- assertTrue("Test Sequence: AAA", sc.inAcceptState());
- }
-}
+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;
+
+public class TestStatePattern {
+
+ StateContext sc;
+
+ @Before
+ public void setUp() {
+ sc = new StateContext();
+ }
+
+ /*
+ * Test Sequence: A
+ */
+ @Test
+ public void test_1() {
+ sc.actionA();
+ assertFalse("Test Sequence A", sc.inAcceptState());
+ }
+
+ /*
+ * Test Sequence: AA
+ */
+ @Test
+ public void test_2() {
+ sc.actionA();
+ sc.actionA();
+ assertTrue("Test Sequence AA", sc.inAcceptState());
+ }
+
+ /*
+ * Test Sequence: A (check state)
+ */
+ @Test
+ public void test_3() {
+ sc.actionA();
+ assertTrue("Test Sequence: A (check state)", sc.getCurrentState().equals(sc.state2));
+ }
+
+ /*
+ * Test Sequence: AAB (check state)
+ */
+ @Test
+ public void test_4() {
+ sc.actionA();
+ sc.actionA();
+ sc.actionB();
+ assertTrue("Test Sequence: AAB (check state)", sc.getCurrentState().equals(sc.state2));
+ }
+
+ /*
+ * Test Sequence: AABB (check state)
+ */
+ @Test
+ public void test_5() {
+ sc.actionA();
+ sc.actionA();
+ sc.actionB();
+ sc.actionB();
+ assertTrue("Test Sequence: AABB (check state)", sc.getCurrentState().equals(sc.state1));
+ }
+
+ /*
+ * Test Sequence: AAA
+ */
+ @Test
+ public void test_6() {
+ sc.actionA();
+ sc.actionA();
+ sc.actionA();
+ assertTrue("Test Sequence: AAA", sc.inAcceptState());
+ }
+}
diff --git a/stateexercise-361.iml b/stateexercise-361.iml
new file mode 100644
index 0000000..0ce27e7
--- /dev/null
+++ b/stateexercise-361.iml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file