diff --git a/Automata/Automata.iml b/Automata/Automata.iml new file mode 100644 index 0000000..c035f0b --- /dev/null +++ b/Automata/Automata.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Automata/out/artifacts/Automata_jar/Automata.jar b/Automata/out/artifacts/Automata_jar/Automata.jar new file mode 100644 index 0000000..33819dc Binary files /dev/null and b/Automata/out/artifacts/Automata_jar/Automata.jar differ diff --git a/Automata/pom.xml b/Automata/pom.xml new file mode 100644 index 0000000..eab3b48 --- /dev/null +++ b/Automata/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + org.example + Java-lab-5 + 1.0-SNAPSHOT + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + ${project.basedir}/src/main/resources + + + + \ No newline at end of file diff --git a/Automata/src/META-INF/MANIFEST.MF b/Automata/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..440fa71 --- /dev/null +++ b/Automata/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: sample.Main + diff --git a/Automata/src/main/java/sample/Automata.java b/Automata/src/main/java/sample/Automata.java new file mode 100644 index 0000000..7a441a6 --- /dev/null +++ b/Automata/src/main/java/sample/Automata.java @@ -0,0 +1,138 @@ +package sample; +import java.util.ArrayList; + +public class Automata { + enum STATES {OFF, WAIT, ACCEPT, CHECK, COOK} + private int cash; + private int change; + + public void setMenu() { + menu.add("Эспрессо 60 мл."); + menu.add("Американо"); + menu.add("Кофе с молоком"); + menu.add("Капучино"); + menu.add("Латте"); + menu.add("Двойной эспрессо"); + menu.add("Мокачино"); + menu.add("Шоколад"); + menu.add("Двойной шоколад"); + menu.add("Кофе с шоколадом"); + menu.add("Шоколад с молоком"); + menu.add("Капучино Амаретто"); + } + + public void setPrices() { + prices.add(25); + prices.add(25); + prices.add(25); + prices.add(30); + prices.add(30); + prices.add(40); + prices.add(35); + prices.add(25); + prices.add(30); + prices.add(25); + prices.add(30); + prices.add(30); + } + + private ArrayList menu = new ArrayList<>(); + private ArrayList prices = new ArrayList<>(); + private STATES state; + private String message; + public Automata() { + cash = 0; + state = STATES.OFF; + } + public ArrayList getMenu(){ + return menu; + } + public ArrayList getPrices(){ + return prices; + } + public int getCash(){ + return cash; + } + public int getChange(){ + return change; + } + public STATES getState(){ + return state; + } + public String getMessage() { + return message; + } + public void on(){ + if(state.equals(STATES.OFF)){ + message="Внесите деньги!"; + state = STATES.WAIT;} + else + message="Некорректная операция!"; + } + public void coin(int value){ + if(state.equals(STATES.WAIT)){ + change=0; + cash+=value; + state=STATES.ACCEPT; + message="Выберите напиток!"; + } + else if(state.equals(STATES.ACCEPT)){ + cash+=value; + } + else + message="Некорректная операция!"; + } + public int choice(int numberOfButton){ + int price=0; + if(state.equals(STATES.ACCEPT)){ + price = prices.get(numberOfButton); + state = STATES.CHECK; + } + else + message="Некорректная операция!"; + return price; + } + public boolean check(int price){ + boolean check = false; + if(state.equals(STATES.CHECK)){ + if (cash cbCash; + @FXML + private ProgressIndicator piProgress; + @FXML + private ImageView ivCup; + + List menu; + List price; + Automata automata; + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + automata = new Automata(); + automata.setMenu(); + automata.setPrices(); + menu = automata.getMenu(); + price = automata.getPrices(); + setComboBox(); + setLblNames(); + setlblPrices(); + ivCup.setVisible(false); + } + + public void setLblNames(){ + String nameLeft1 = menu.get(0); + lblNameLeft1.setText(nameLeft1); + String nameLeft2 = menu.get(1); + lblNameLeft2.setText(nameLeft2); + String nameLeft3 = menu.get(2); + lblNameLeft3.setText(nameLeft3); + String nameLeft4 = menu.get(3); + lblNameLeft4.setText(nameLeft4); + String nameLeft5 = menu.get(4); + lblNameLeft5.setText(nameLeft5); + String nameLeft6 = menu.get(5); + lblNameLeft6.setText(nameLeft6); + String nameRight1 = menu.get(6); + lblNameRight1.setText(nameRight1); + String nameRight2 = menu.get(7); + lblNameRight2.setText(nameRight2); + String nameRight3 = menu.get(8); + lblNameRight3.setText(nameRight3); + String nameRight4 = menu.get(9); + lblNameRight4.setText(nameRight4); + String nameRight5 = menu.get(10); + lblNameRight5.setText(nameRight5); + String nameRight6 = menu.get(11); + lblNameRight6.setText(nameRight6); + } + + public void setlblPrices(){ + String priceLeft1 = price.get(0).toString(); + lblPriceLeft1.setText(priceLeft1); + String priceLeft2 = price.get(1).toString(); + lblPriceLeft2.setText(priceLeft2); + String priceLeft3 = price.get(2).toString(); + lblPriceLeft3.setText(priceLeft3); + String priceLeft4 = price.get(3).toString(); + lblPriceLeft4.setText(priceLeft4); + String priceLeft5 = price.get(4).toString(); + lblPriceLeft5.setText(priceLeft5); + String priceLeft6 = price.get(5).toString(); + lblPriceLeft6.setText(priceLeft6); + String priceRight1 = price.get(6).toString(); + lblPriceRight1.setText(priceRight1); + String priceRight2 = price.get(7).toString(); + lblPriceRight2.setText(priceRight2); + String priceRight3 = price.get(8).toString(); + lblPriceRight3.setText(priceRight3); + String priceRight4 = price.get(9).toString(); + lblPriceRight4.setText(priceRight4); + String priceRight5 = price.get(10).toString(); + lblPriceRight5.setText(priceRight5); + String priceRight6 = price.get(11).toString(); + lblPriceRight6.setText(priceRight6); + } + + public void switchOn(){ + automata.on(); + lblMessage.setText(automata.getMessage()); + } + + public void switchOff(){ + automata.off(); + lblMessage.setText(automata.getMessage()); + piProgress.setProgress(0); + } + + public void setComboBox(){ + ObservableList cashAvailable = FXCollections.observableArrayList(5,10,50,100); + cbCash.setItems(cashAvailable); + } + + public void getCash(){ + try { + int cash = cbCash.getValue(); + automata.coin(cash); + lblMessage.setText(automata.getMessage()); + } + catch (java.lang.NullPointerException e){}; + } + + public void btnLeft1Pressed(){ + choiceAndCook(0); + } + public void btnLeft2Pressed(){ + choiceAndCook(1); + } + public void btnLeft3Pressed(){ + choiceAndCook(2); + } + public void btnLeft4Pressed(){ + choiceAndCook(3); + } + public void btnLeft5Pressed(){ + choiceAndCook(4); + } + public void btnLeft6Pressed(){ + choiceAndCook(5); + } + public void btnRight1Pressed(){ + choiceAndCook(6); + } + public void btnRight2Pressed(){ + choiceAndCook(7); + } + public void btnRight3Pressed(){ + choiceAndCook(8); + } + public void btnRight4Pressed(){ + choiceAndCook(9); + } + public void btnRight5Pressed(){ + choiceAndCook(10); + } + public void btnRight6Pressed() { choiceAndCook(11); } + + public void choiceAndCook (int number) { + int price = automata.choice(number); + lblMessage.setText(automata.getMessage()); + boolean check = automata.check(price); + if(check) { + Integer change = automata.getChange(); + try { + cbCash.setValue(null); + } + catch (java.lang.NullPointerException e){}; + lblChange.setText(change.toString()); + new Thread(() -> { + cook(number, piProgress, lblMessage, ivCup); + }).start(); + } + else + lblMessage.setText("недостаточно денег!"); + } + + public void cook(int number, ProgressIndicator piProgress, Label lblMessage, ImageView ivCup){ + automata.cook(); + try { + for(int i=0; i<=100; i++) { + Thread.sleep(50); + Double progress=(double)i/100; + Platform.runLater(() -> { + piProgress.setProgress(progress); + if (piProgress.getProgress()<1) + lblMessage.setText(menu.get(number) + " готовится"); + else { + lblMessage.setText(menu.get(number) + " готов!"); + ivCup.setVisible(true); + } + }); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + public void cancel(){ + automata.cancel(); + Integer change = automata.getChange(); + lblChange.setText(change.toString()); + try { + cbCash.setValue(null); + } + catch (java.lang.NullPointerException e){}; + lblMessage.setText(automata.getMessage()); + } +} diff --git a/Automata/src/main/java/sample/Main.java b/Automata/src/main/java/sample/Main.java new file mode 100644 index 0000000..b6ef15b --- /dev/null +++ b/Automata/src/main/java/sample/Main.java @@ -0,0 +1,23 @@ +package sample; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public class Main extends Application { + + @Override + public void start(Stage primaryStage) throws Exception{ + Parent root = FXMLLoader.load(getClass().getResource("/sample.fxml")); + primaryStage.setTitle("Automata"); + primaryStage.setScene(new Scene(root)); + primaryStage.show(); + } + + + public static void main(String[] args) { + launch(args); + } +} diff --git a/Automata/src/main/resources/Automata.jpg b/Automata/src/main/resources/Automata.jpg new file mode 100644 index 0000000..234f2a9 Binary files /dev/null and b/Automata/src/main/resources/Automata.jpg differ diff --git a/Automata/src/main/resources/cup.png b/Automata/src/main/resources/cup.png new file mode 100644 index 0000000..f40cbea Binary files /dev/null and b/Automata/src/main/resources/cup.png differ diff --git a/Automata/src/main/resources/sample.fxml b/Automata/src/main/resources/sample.fxml new file mode 100644 index 0000000..569c5ae --- /dev/null +++ b/Automata/src/main/resources/sample.fxml @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +