Skip to content
Open

ok #120

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
3 changes: 3 additions & 0 deletions .idea/.gitignore

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.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.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.

86 changes: 86 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>Automata_Demo</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>


</project>
122 changes: 122 additions & 0 deletions src/main/java/Automata.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
24 changes: 24 additions & 0 deletions src/main/java/Automata_Demo.java
Original file line number Diff line number Diff line change
@@ -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());


}
}
50 changes: 50 additions & 0 deletions src/test/java/Automata_test.java
Original file line number Diff line number Diff line change
@@ -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());
}
}