diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..29c722a
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,29 @@
+
+
+ 4.0.0
+
+ Automata
+ Automata
+ 1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 1.8
+ 1.8
+
+
+
+
+
+
+ junit
+ junit
+ RELEASE
+
+
+
diff --git a/src/main/java/Automata.java b/src/main/java/Automata.java
new file mode 100644
index 0000000..3a37d65
--- /dev/null
+++ b/src/main/java/Automata.java
@@ -0,0 +1,100 @@
+import java.util.HashMap;
+public class Automata {
+
+ enum STATES {
+ OFF, WAIT, ACCEPT, CHECK, COOK
+ }
+
+ private int cash;
+ private STATES state;
+
+ static HashMap prices = new HashMap();
+ static {
+ prices.put("1", "Coffee with milk,30");
+ prices.put("2", "Green Tea,40");
+ prices.put("3", "Cappuchino,50");
+ prices.put("4", "Latthe,30");
+ prices.put("5", "Orange Juice,40");
+ }
+
+ public Automata() {
+ state = STATES.OFF;
+ this.cash = 0;
+ }
+
+ public STATES getState() {
+ return state;
+ }
+
+ public void setState(STATES state) {
+ this.state = state;
+ }
+
+ public int getCash() {
+ return cash;
+ }
+
+ public void setCash(int cash) {
+ this.cash = cash;
+ }
+
+ public void on() {
+ if (state == STATES.OFF) {
+ state = STATES.WAIT;
+ }
+ }
+
+ public void off() {
+ state = STATES.OFF;
+ }
+
+ public void coin(int amount) {
+ if (state == STATES.WAIT || state == STATES.ACCEPT) {
+ state = STATES.ACCEPT;
+ cash +=amount;
+ }
+ }
+ public void choice(String menuNum) {
+ if (state != STATES.OFF) {
+ if (check(menuNum)) {
+ cook(menuNum);
+ } else {
+ cancel();
+ }
+ }
+ }
+
+ private boolean check(String menuNum) {
+ state = STATES.CHECK;
+ return Integer.parseInt(prices.get(menuNum).split(",")[1]) <= cash;
+ }
+
+ public void printState() {
+ System.out.println("Current state is " + state);
+ }
+
+ public void printMenu(){
+ prices.forEach((k,v) -> System.out.println(" "+k+" "+v));
+ }
+
+ private void cook (String menuNum){
+ state = STATES.COOK;
+ finish(menuNum);
+ }
+
+ public int cancel() {
+ int sum = cash;
+ if (state == STATES.ACCEPT || state == STATES.CHECK ) {
+ cash = 0;
+ state = STATES.WAIT;
+ } else {
+ sum = -1;
+ }
+ return sum;
+ }
+
+ private void finish(String menuNum){
+ state = STATES.WAIT;
+ cash -= Integer.parseInt(prices.get(menuNum).split(",")[1]);
+ }
+}
diff --git a/src/main/java/main.java b/src/main/java/main.java
new file mode 100644
index 0000000..2d0f536
--- /dev/null
+++ b/src/main/java/main.java
@@ -0,0 +1,13 @@
+class main {
+ public static void main(String[] args) {
+ Automata automata = new Automata();
+ automata.on();
+ automata.printState();
+ automata.printMenu();
+ automata.coin(50);
+ automata.printState();
+ automata.choice("5");
+ automata.printState();
+ automata.off();
+ }
+}
diff --git a/src/test/java/AutomataTest.java b/src/test/java/AutomataTest.java
new file mode 100644
index 0000000..1b70b4e
--- /dev/null
+++ b/src/test/java/AutomataTest.java
@@ -0,0 +1,54 @@
+import static org.junit.Assert.*;
+
+import static org.junit.Assert.*;
+
+public class AutomataTest {
+
+ @org.junit.Test
+ public void on() {
+ Automata a = new Automata();
+ a.on();
+ assertEquals(Automata.STATES.WAIT, a.getState());
+ assertEquals(0, a.getCash());
+ }
+
+ @org.junit.Test
+ public void off() {
+ Automata a = new Automata();
+ a.on();
+ a.off();
+ assertEquals(Automata.STATES.OFF, a.getState());
+ }
+
+ @org.junit.Test
+ public void coin() {
+ Automata a = new Automata();
+ a.on();
+ a.coin(20);
+ a.coin(20);
+ assertEquals(40, a.getCash());
+ }
+
+ @org.junit.Test
+ public void choice() {
+ Automata a = new Automata();
+ a.on();
+ a.coin(50);
+ assertEquals(50, a.getCash());
+ a.choice("3");
+ assertEquals(0, a.getCash());
+ a.coin(40);
+ a.choice("4");
+ assertEquals(10, a.getCash());
+ }
+
+ @org.junit.Test
+ public void cancel() {
+ Automata testAutomata = new Automata();
+ testAutomata.on();
+ testAutomata.coin(50);
+ assertEquals(50, testAutomata.getCash());
+ testAutomata.cancel();
+ assertEquals(0, testAutomata.getCash());
+ }
+}