From 7e27f4ff7fe53de1eaa945af21e42fcda3c8638b Mon Sep 17 00:00:00 2001
From: Peter <57073925+Pitonnov@users.noreply.github.com>
Date: Fri, 28 Aug 2020 13:12:14 +0300
Subject: [PATCH] done
---
.idea/.gitignore | 3 +
.idea/compiler.xml | 13 ++++
.idea/jarRepositories.xml | 20 +++++
.idea/misc.xml | 14 ++++
pom.xml | 86 ++++++++++++++++++++++
src/main/java/Automata.java | 122 +++++++++++++++++++++++++++++++
src/main/java/Automata_Demo.java | 24 ++++++
src/test/java/Automata_test.java | 50 +++++++++++++
8 files changed, 332 insertions(+)
create mode 100644 .idea/.gitignore
create mode 100644 .idea/compiler.xml
create mode 100644 .idea/jarRepositories.xml
create mode 100644 .idea/misc.xml
create mode 100644 pom.xml
create mode 100644 src/main/java/Automata.java
create mode 100644 src/main/java/Automata_Demo.java
create mode 100644 src/test/java/Automata_test.java
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..ec7c6b0
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..712ab9d
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..4b661a5
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..bd9b9af
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,86 @@
+
+
+ 4.0.0
+
+ org.example
+ Automata_Demo
+ 1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 7
+ 7
+
+
+
+
+
+
+ junit
+ junit
+ 4.11
+ test
+
+
+ junit
+ junit
+ 4.11
+ test
+
+
+ junit
+ junit
+ 4.11
+ test
+
+
+ junit
+ junit
+ 4.11
+ test
+
+
+ junit
+ junit
+ 4.11
+ test
+
+
+ junit
+ junit
+ 4.11
+ test
+
+
+ junit
+ junit
+ 4.11
+ test
+
+
+ junit
+ junit
+ 4.11
+ test
+
+
+ junit
+ junit
+ 4.11
+ test
+
+
+ junit
+ junit
+ 4.11
+ test
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/Automata.java b/src/main/java/Automata.java
new file mode 100644
index 0000000..97484e9
--- /dev/null
+++ b/src/main/java/Automata.java
@@ -0,0 +1,122 @@
+public class Automata {
+ private enum My_States {ON, WAIT, ACCEPT, CHECK, COOK, OFF};
+ private My_States States;
+ private int cash;
+ private String[] Menuout = new String[]{"Black Tea", "Latte", "Cappuccino", "Glace", "Green Tea",
+ "Hot chocolate", "Espresso"};
+ private int[] prices = new int[]{30, 45, 50, 60, 30, 40, 35};
+ private long Timer = 0;
+
+ public String getMenu() {
+ String Out = "<---------MENU---------->\n";
+ for (int i = 0; i < Menuout.length; i++) {
+ int u = i + 1;
+ Out = Out + "\\ " + u + " | " + Menuout[i] + " | " + prices[i] + " /" + "\n";
+ }
+ Out = Out + "___________End___________\n";
+ return Out;
+ }
+
+ public String On() {
+ if (States != My_States.COOK) {
+ States = My_States.WAIT;
+ }
+ return "CoffeeMaker on";
+ }
+
+ private void Cook(int choice) {
+ States = States.COOK;
+ Timer = System.currentTimeMillis();
+ }
+
+ public String Finish() {
+ if (States == States.OFF) {
+ return "CoffeeMaker off";
+ }
+ if ((System.currentTimeMillis() - Timer) > 5000) {
+ States = States.WAIT;
+ return "Your drink is ready, bro";
+ } else {
+ return "Your drink is cooking, wait, bro";
+ }
+ }
+
+ public boolean Check(int choice) {
+ if (prices[choice - 1] > cash) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ public String getState() { // - отображение текущего состояния для пользователя;
+ return String.valueOf(States);
+ }
+
+ public String Choice(int choice) {
+ if (States == States.OFF) {
+ return "CoffeeMaker off";
+ }
+ if (choice <= 0 || choice > Menuout.length) {
+ return "This drink was not find, select another.";
+ } else {
+ States = States.CHECK;
+ if (!Check(choice)) {
+ States = States.ACCEPT;
+ return "Not enough cash, man, add yet " + (prices[choice - 1] - cash);
+ } else {
+ cash = cash - prices[choice - 1];
+ Cook(choice);
+ return "I understood and make for you " + Menuout[choice - 1];
+ }
+ }
+ }
+
+ public String off() {
+ if (States == States.WAIT && cash == 0){
+ States = States.OFF;
+ return "CoffeeMaker off";
+ }
+ else if (States == States.WAIT && cash > 0){
+ return "Before off, give your cash or choose drink, man.";
+ }
+ else{
+ return "Wait, I am busy.";
+ }
+ }
+
+ public String coin(int money) {
+ if (States == States.OFF){
+ return "CoffeeMaker off";
+ }
+ States = States.ACCEPT;
+ if (money <= 0){
+ return "What is this? Try again.";
+ }
+ cash = cash + money;
+ cancel();
+ return "I have "+cash+" coins.";
+ }
+
+ public void cancel(){
+ States = States.WAIT;
+ }
+
+ public int getCoin(){
+ return cash;
+ }
+
+ public String moneyBack(){
+ if (States == States.OFF){
+ return "CoffeeMaker off";
+ }
+ if (cash==0){
+ return "I don't have your coins";
+ }
+ else {
+ String text = "Give your payback " + cash;
+ cash = 0;
+ return text;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/Automata_Demo.java b/src/main/java/Automata_Demo.java
new file mode 100644
index 0000000..9f5d2d6
--- /dev/null
+++ b/src/main/java/Automata_Demo.java
@@ -0,0 +1,24 @@
+import java.awt.*;
+
+public class Automata_Demo {
+ public static void main (String[] args) throws InterruptedException {
+ Automata work = new Automata();
+ System.out.println("Hello, my hungry friend!");
+ System.out.println(work.On());
+ System.out.println(work.getMenu());
+ System.out.println(work.Choice(0));
+ System.out.println(work.coin(15));
+ System.out.println(work.Choice(3));
+ System.out.println(work.coin(50));
+ System.out.println(work.Choice(3));
+ System.out.println(work.Finish());
+ Thread.sleep(6000);
+ System.out.println(work.Finish());
+ System.out.println(work.off());
+ System.out.println(work.moneyBack());
+ System.out.println(work.off());
+ System.out.println(work.getState());
+
+
+ }
+}
diff --git a/src/test/java/Automata_test.java b/src/test/java/Automata_test.java
new file mode 100644
index 0000000..63b0ac8
--- /dev/null
+++ b/src/test/java/Automata_test.java
@@ -0,0 +1,50 @@
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class Automata_test {
+
+ Automata Test = new Automata();
+
+ @Test
+ public void on() {
+ Test.On();
+ assertEquals("WAIT",Test.getState());
+ }
+
+ @Test
+ public void off() {
+ Test.On();
+ Test.coin(40);
+ Test.off();
+ assertEquals("WAIT",Test.getState());
+ Test.moneyBack();
+ Test.off();
+ assertEquals("OFF",Test.getState());
+ }
+
+ @Test
+ public void coin() {
+ Test.On();
+ assertEquals("What is this? Try again.",Test.coin(0));
+ Test.coin(50);
+ assertEquals(50,Test.getCoin());
+ }
+
+ @Test
+ public void moneyBack() {
+ Test.On();
+ assertEquals("I don't have your coins",Test.moneyBack());
+ Test.coin(50);
+ Test.moneyBack();
+ assertEquals(0,Test.getCoin());
+ }
+
+ @Test
+ public void choice() {
+ Test.On();
+ Test.coin(50);
+ Test.Choice(1);
+ assertEquals("COOK", Test.getState());
+ }
+}
\ No newline at end of file