diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index dff5f3a..0000000 --- a/.travis.yml +++ /dev/null @@ -1 +0,0 @@ -language: java diff --git a/AutomataGUIDemo/.idea/artifacts/AutomataGUIDemo_jar.xml b/AutomataGUIDemo/.idea/artifacts/AutomataGUIDemo_jar.xml new file mode 100644 index 0000000..2e9c417 --- /dev/null +++ b/AutomataGUIDemo/.idea/artifacts/AutomataGUIDemo_jar.xml @@ -0,0 +1,13 @@ + + + $PROJECT_DIR$/out/artifacts/AutomataGUIDemo_jar + + + + + + + + + + \ No newline at end of file diff --git a/AutomataGUIDemo/.idea/compiler.xml b/AutomataGUIDemo/.idea/compiler.xml new file mode 100644 index 0000000..ab146be --- /dev/null +++ b/AutomataGUIDemo/.idea/compiler.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AutomataGUIDemo/.idea/description.html b/AutomataGUIDemo/.idea/description.html new file mode 100644 index 0000000..cc10d56 --- /dev/null +++ b/AutomataGUIDemo/.idea/description.html @@ -0,0 +1,2 @@ +Simple JavaFX 2.0 application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided. + \ No newline at end of file diff --git a/AutomataGUIDemo/.idea/encodings.xml b/AutomataGUIDemo/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/AutomataGUIDemo/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AutomataGUIDemo/.idea/gradle.xml b/AutomataGUIDemo/.idea/gradle.xml new file mode 100644 index 0000000..3e3960b --- /dev/null +++ b/AutomataGUIDemo/.idea/gradle.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/AutomataGUIDemo/.idea/libraries/Maven__commons_io_commons_io_2_1.xml b/AutomataGUIDemo/.idea/libraries/Maven__commons_io_commons_io_2_1.xml new file mode 100644 index 0000000..3b78142 --- /dev/null +++ b/AutomataGUIDemo/.idea/libraries/Maven__commons_io_commons_io_2_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/AutomataGUIDemo/.idea/libraries/Maven__junit_junit_4_13.xml b/AutomataGUIDemo/.idea/libraries/Maven__junit_junit_4_13.xml new file mode 100644 index 0000000..59fc5c4 --- /dev/null +++ b/AutomataGUIDemo/.idea/libraries/Maven__junit_junit_4_13.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/AutomataGUIDemo/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/AutomataGUIDemo/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/AutomataGUIDemo/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/AutomataGUIDemo/.idea/libraries/Maven__org_json_json_20090211.xml b/AutomataGUIDemo/.idea/libraries/Maven__org_json_json_20090211.xml new file mode 100644 index 0000000..e57dc0a --- /dev/null +++ b/AutomataGUIDemo/.idea/libraries/Maven__org_json_json_20090211.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/AutomataGUIDemo/.idea/misc.xml b/AutomataGUIDemo/.idea/misc.xml new file mode 100644 index 0000000..6d5ac1a --- /dev/null +++ b/AutomataGUIDemo/.idea/misc.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/AutomataGUIDemo/.idea/modules.xml b/AutomataGUIDemo/.idea/modules.xml new file mode 100644 index 0000000..b3b29a6 --- /dev/null +++ b/AutomataGUIDemo/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/AutomataGUIDemo/.idea/uiDesigner.xml b/AutomataGUIDemo/.idea/uiDesigner.xml new file mode 100644 index 0000000..3b00020 --- /dev/null +++ b/AutomataGUIDemo/.idea/uiDesigner.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutomataGUIDemo/.idea/vcs.xml b/AutomataGUIDemo/.idea/vcs.xml new file mode 100644 index 0000000..def6a6a --- /dev/null +++ b/AutomataGUIDemo/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/AutomataGUIDemo/.idea/workspace.xml b/AutomataGUIDemo/.idea/workspace.xml new file mode 100644 index 0000000..7131d5c --- /dev/null +++ b/AutomataGUIDemo/.idea/workspace.xml @@ -0,0 +1,294 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + 5050 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1359379246138 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AutomataGUIDemo/AutomataGUIDemo.iml b/AutomataGUIDemo/AutomataGUIDemo.iml new file mode 100644 index 0000000..f2a86ab --- /dev/null +++ b/AutomataGUIDemo/AutomataGUIDemo.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AutomataGUIDemo/META-INF/MANIFEST.MF b/AutomataGUIDemo/META-INF/MANIFEST.MF new file mode 100644 index 0000000..440fa71 --- /dev/null +++ b/AutomataGUIDemo/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: sample.Main + diff --git a/AutomataGUIDemo/menu.json b/AutomataGUIDemo/menu.json new file mode 100644 index 0000000..40ff455 --- /dev/null +++ b/AutomataGUIDemo/menu.json @@ -0,0 +1,50 @@ +{ + "menu": [ + "Эспрессо", + "Латте", + "Мокко", + "Флэт Вайт", + "Каппучино", + "Маккиато", + "Фредо", + "Романо", + "Медовый Раф", + "Гляссе", + "Ристретто", + "Лунго", + "Американо", + "Латте", + "Кон панна", + "Бревэ", + "Айриш", + "Корретто", + "Раф кофе", + "Триппло", + "Марочино", + "Бичерин" + ], + "prices": [ + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0, + 100.0 + ] +} diff --git a/AutomataGUIDemo/out/artifacts/AutomataGUIDemo_jar/AutomataGUIDemo.jar b/AutomataGUIDemo/out/artifacts/AutomataGUIDemo_jar/AutomataGUIDemo.jar new file mode 100644 index 0000000..bb40ff7 Binary files /dev/null and b/AutomataGUIDemo/out/artifacts/AutomataGUIDemo_jar/AutomataGUIDemo.jar differ diff --git a/AutomataGUIDemo/pom.xml b/AutomataGUIDemo/pom.xml new file mode 100644 index 0000000..4aeaf9a --- /dev/null +++ b/AutomataGUIDemo/pom.xml @@ -0,0 +1,61 @@ + + + 4.0.0 + + nniit + AutomataGUIDemo + 1.0-SNAPSHOT + + + + org.json + json + 20090211 + + + commons-io + commons-io + 2.1 + + + junit + junit + 4.13 + test + + + junit + junit + 4.13 + test + + + junit + junit + 4.13 + test + + + junit + junit + 4.13 + test + + + junit + junit + 4.13 + test + + + junit + junit + 4.13 + test + + + + + \ No newline at end of file diff --git a/AutomataGUIDemo/src/main/java/AutomataDemo/Automata.java b/AutomataGUIDemo/src/main/java/AutomataDemo/Automata.java new file mode 100644 index 0000000..88e7b1d --- /dev/null +++ b/AutomataGUIDemo/src/main/java/AutomataDemo/Automata.java @@ -0,0 +1,112 @@ +package AutomataDemo; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import org.apache.commons.io.FileUtils; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +public class Automata { + private STATES state; + private float cash; + private static final HashMap menu = new HashMap<>(); + + public Automata() throws IOException, JSONException { + readJSON(); + state = STATES.OFF; + } + + private static void readJSON() throws IOException, JSONException { + File file = new File("menu.json"); + String content = FileUtils.readFileToString(file, "utf-8"); + JSONObject jsonMenu = new JSONObject(content); + JSONArray arrayMenu = jsonMenu.getJSONArray("menu"); + JSONArray arrayPrices = jsonMenu.getJSONArray("prices"); + for(int i = 0; i < arrayMenu.length(); i++){ + double temp = (double)arrayPrices.get(i); + menu.put((String)arrayMenu.get(i), (float)temp); + } + } + + //возврат денежных средств (сдачи) покупателю + private void refunds(float amount){ + if (cash >= amount) + cash -= amount; + } + + //списание цены за напиток + private void writeoff(float amount){ + if (cash >= amount) + cash -= amount; + } + + private boolean check(float amount){ + return (cash >= amount)? true : false; + } + + public void on(){ + if(state == STATES.OFF){ + state = STATES.ON; + } + } + + public void coin(float amount){ + if(state == STATES.WAIT || state == STATES.ACCEPT){ + cash += amount; + state = STATES.ACCEPT; + } + } + + public void choice(String key){ + //выбор напитка покупателем + if (state == STATES.ACCEPT){ + state = STATES.CHECK; + float price = menu.get(key); + if (check(price)){ + state = STATES.COOK; + writeoff(price); //списана цена напитка + if (cash > 0){ + state = STATES.ACCEPT; //есть ещё средства, можно дополнить и купить что-нибудь ещё //вывести в интерфей информацию об остатке + } else { + state = STATES.WAIT; + } + } else { + state = STATES.ACCEPT; + } + } + } + + public void off(){ + if (state == STATES.ON || state == STATES.WAIT) + state = STATES.OFF; + else if (state == STATES.ACCEPT){ + refunds(cash); + state = STATES.OFF; + } + } + + public HashMap getMenu(){ + if (state == STATES.ON) + state = STATES.WAIT; + return menu; + } + + public STATES getState(){ + return this.state; + } + + public void cancel(){ + if (state == STATES.WAIT){ + state = STATES.ON; + } else if (state == STATES.ACCEPT){ + this.state = STATES.WAIT; + refunds(cash); + } + } + + public float getCash(){ + return cash; + } +} diff --git a/AutomataGUIDemo/src/main/java/AutomataDemo/STATES.java b/AutomataGUIDemo/src/main/java/AutomataDemo/STATES.java new file mode 100644 index 0000000..04b4f4f --- /dev/null +++ b/AutomataGUIDemo/src/main/java/AutomataDemo/STATES.java @@ -0,0 +1,10 @@ +package AutomataDemo; + +public enum STATES{ + ON, + OFF, + WAIT, + ACCEPT, + CHECK, + COOK +} diff --git a/AutomataGUIDemo/src/main/java/sample/Controller.java b/AutomataGUIDemo/src/main/java/sample/Controller.java new file mode 100644 index 0000000..8e0a0ac --- /dev/null +++ b/AutomataGUIDemo/src/main/java/sample/Controller.java @@ -0,0 +1,381 @@ +package sample; +import AutomataDemo.Automata; +import AutomataDemo.STATES; +import javafx.concurrent.Task; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.ProgressBar; +import javafx.scene.control.TextField; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.Pane; +import org.json.JSONException; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.ResourceBundle; + +class CookTask extends Task { + private GridPane gridPane; + + public CookTask(GridPane gridPane){ + this.gridPane = gridPane; + } + @Override + protected Boolean call() throws Exception { + gridPane.setMouseTransparent(true); + + for(int i=0; i<100; i++){ + this.cook(); + this.updateProgress(i, 100); + this.updateMessage("Идёт приготовление напитка ... " + i + "%"); + } + this.updateProgress(0, 0); + gridPane.setMouseTransparent(false); + return true; + } + + private void cook() throws InterruptedException { + Thread.sleep(100); + } +} + +public class Controller implements Initializable { + private Automata atmt; + private HashMap prices; + private List keys = new ArrayList<>(); + + @FXML + private ProgressBar progressBar; + + @FXML + private GridPane gridPane; + + @FXML + private Label lbInstruction; + + @FXML + private Pane pane; + + @FXML + private Label lbMessage; + + @FXML + private Button btnOnOff; + + + @FXML + private Button btnComplete; + + @FXML + private Button btnPay; + + @FXML + private TextField tfAmount; + + @FXML + private Button btn11; + @FXML + private Button btn12; + @FXML + private Label label111; + @FXML + private Label label112; + @FXML + private Label label121; + @FXML + private Label label122; + @FXML + private Button btn21; + @FXML + private Button btn22; + @FXML + private Label label211; + @FXML + private Label label212; + @FXML + private Label label221; + @FXML + private Label label222; + @FXML + private Button btn31; + @FXML + private Button btn32; + @FXML + private Label label311; + @FXML + private Label label312; + @FXML + private Label label321; + @FXML + private Label label322; + @FXML + private Button btn41; + @FXML + private Button btn42; + @FXML + private Label label411; + @FXML + private Label label412; + @FXML + private Label label421; + @FXML + private Label label422; + @FXML + private Button btn51; + @FXML + private Button btn52; + @FXML + private Label label511; + @FXML + private Label label512; + @FXML + private Label label521; + @FXML + private Label label522; + @FXML + private Button btn61; + @FXML + private Button btn62; + @FXML + private Label label611; + @FXML + private Label label612; + @FXML + private Label label621; + @FXML + private Label label622; + + @FXML + public void btn11Click() throws InterruptedException { + String key = label111.getText(); + btnClick(key, prices.get(key)); + } + + @FXML + public void btn12Click() throws InterruptedException { + String key = label121.getText(); + btnClick(key, prices.get(key)); + } + + @FXML + public void btn21Click() throws InterruptedException { + String key = label211.getText(); + btnClick(key, prices.get(key)); + } + + @FXML + public void btn22Click() throws InterruptedException { + String key = label221.getText(); + btnClick(key, prices.get(key)); + } + + @FXML + public void btn31Click() throws InterruptedException { + String key = label311.getText(); + btnClick(key, prices.get(key)); + } + + @FXML + public void btn32Click() throws InterruptedException { + String key = label321.getText(); + btnClick(key, prices.get(key)); + } + + @FXML + public void btn41Click() throws InterruptedException { + String key = label411.getText(); + btnClick(key, prices.get(key)); + } + + @FXML + public void btn42Click() throws InterruptedException { + String key = label421.getText(); + btnClick(key, prices.get(key)); + } + + @FXML + public void btn51Click() throws InterruptedException { + String key = label511.getText(); + btnClick(key, prices.get(key)); + } + + @FXML + public void btn52Click() throws InterruptedException { + String key = label521.getText(); + btnClick(key, prices.get(key)); + } + + @FXML + public void btn61Click() throws InterruptedException { + String key = label611.getText(); + btnClick(key, prices.get(key)); + } + + @FXML + public void btn62Click() throws InterruptedException { + String key = label621.getText(); + btnClick(key, prices.get(key)); + } + + @FXML + public void btnOnOffClick(){ + + if(atmt.getState() == STATES.OFF){ + gridPane.setVisible(true); + atmt.on(); + atmt.getMenu(); + lbMessage.setText(""); + } else { + if(atmt.getCash()>0){ + lbMessage.setText(String.format("Выдана сдача %.2f", atmt.getCash())); + } else if (atmt.getCash() == 0){ + lbMessage.setText(""); + } + atmt.off(); + gridPane.setVisible(false); + } + } + + @FXML + public void bntCompleteClick(){ + float temp = atmt.getCash(); + atmt.cancel(); + if (temp > 0){ + lbMessage.setText(String.format("Выдана сдача %.2f.\nНа счете автомата %.2f.", temp, atmt.getCash())); + } else if (temp == 0){ + lbMessage.setText(""); + } + } + + @FXML + public void bntPayClick(){ + try{ + float amount = Float.parseFloat(tfAmount.getText()); + atmt.coin(amount); + lbMessage.setText(String.format("На счете автомата %.2f", atmt.getCash())); + tfAmount.clear(); + + } catch (Exception e){ + lbMessage.setText("Не удалось преобразовать введённое значение к числу.\nПопробуйте внести сумму ещё раз."); + } + + } + + private void btnClick(String key, Float price) throws InterruptedException { + if(atmt.getState() == STATES.ACCEPT){ + if(atmt.getCash() < price){ + lbMessage.setText(String.format("Не хватает средств!\n Стоимость напитка состовляет %.2f. Остаток на счете %.2f.", price, atmt.getCash())); + } else { + CookTask cookTask = new CookTask(gridPane); + progressBar.progressProperty().unbind(); + progressBar.progressProperty().bind(cookTask.progressProperty()); + Thread th = new Thread(cookTask); + th.start(); + //th.join(); + + atmt.choice(key); + lbMessage.setText(String.format("Остаток на счете %.2f", atmt.getCash())); + } + } + } + + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + + //pane.setStyle("-fx-background-color: LINEN"); + //pane.setStyle("-fx-background-color: PAPAYAWHIP"); + pane.setStyle("-fx-background-color: OLDLACE"); + + lbInstruction.setText("Инструкция:\n" + + " 1. Для того, чтобы включить (выключить) устройство, воспользуйтесь командой 'ON / OFF'.\n" + + " 2. Оплатите покупку - введите сумму и воспользуйтесь командой 'Внести'.\n" + + " 3. Для приготовления напитка воспользуйтесь командой расположенной в центре основного меню.\n" + + " 4. Для того, чтобы снять остоток внесенных денежных средств или отменить покупку воспользуйтесь командой 'Завершить'.\n" + + " ВНИМАНИЕ: Отмена покупки невозможна на этапе приготовления напитка."); + + lbInstruction.setStyle("-fx-background-color: WHITE"); + + btnOnOff.setStyle("-fx-background-image: url('/onoff.png')"); + btn11.setStyle("-fx-background-image: url('/icon8.png')"); + btn12.setStyle("-fx-background-image: url('/icon8.png')"); + btn21.setStyle("-fx-background-image: url('/icon8.png')"); + btn22.setStyle("-fx-background-image: url('/icon8.png')"); + btn31.setStyle("-fx-background-image: url('/icon8.png')"); + btn32.setStyle("-fx-background-image: url('/icon8.png')"); + btn41.setStyle("-fx-background-image: url('/icon8.png')"); + btn42.setStyle("-fx-background-image: url('/icon8.png')"); + btn51.setStyle("-fx-background-image: url('/icon8.png')"); + btn52.setStyle("-fx-background-image: url('/icon8.png')"); + btn61.setStyle("-fx-background-image: url('/icon8.png')"); + btn62.setStyle("-fx-background-image: url('/icon8.png')"); + + + try { + atmt = new Automata(); + } catch (IOException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } + atmt.on(); + prices = atmt.getMenu(); + + for(String key : prices.keySet()){ + keys.add(key); + } + + label111.setText(keys.get(0)); + label112.setText("Цена: " + prices.get(keys.get(0))); + label121.setText(keys.get(1)); + label122.setText("Цена: " + prices.get(keys.get(1))); + label211.setText(keys.get(2)); + label212.setText("Цена: " + prices.get(keys.get(2))); + label221.setText(keys.get(3)); + label222.setText("Цена: " + prices.get(keys.get(3))); + label311.setText(keys.get(4)); + label312.setText("Цена: " + prices.get(keys.get(4))); + label321.setText(keys.get(5)); + label322.setText("Цена: " + prices.get(keys.get(5))); + label411.setText(keys.get(6)); + label412.setText("Цена: " + prices.get(keys.get(6))); + label421.setText(keys.get(7)); + label422.setText("Цена: " + prices.get(keys.get(7))); + label511.setText(keys.get(8)); + label512.setText("Цена: " + prices.get(keys.get(8))); + label521.setText(keys.get(9)); + label522.setText("Цена: " + prices.get(keys.get(9))); + label611.setText(keys.get(10)); + label612.setText("Цена: " + prices.get(keys.get(10))); + label621.setText(keys.get(11)); + label622.setText("Цена: " + prices.get(keys.get(11))); + label111.setStyle("-fx-background-color: WHITE"); + label112.setStyle("-fx-background-color: WHITE"); + label121.setStyle("-fx-background-color: WHITE"); + label122.setStyle("-fx-background-color: WHITE"); + label211.setStyle("-fx-background-color: WHITE"); + label212.setStyle("-fx-background-color: WHITE"); + label221.setStyle("-fx-background-color: WHITE"); + label222.setStyle("-fx-background-color: WHITE"); + label311.setStyle("-fx-background-color: WHITE"); + label312.setStyle("-fx-background-color: WHITE"); + label321.setStyle("-fx-background-color: WHITE"); + label322.setStyle("-fx-background-color: WHITE"); + label411.setStyle("-fx-background-color: WHITE"); + label412.setStyle("-fx-background-color: WHITE"); + label421.setStyle("-fx-background-color: WHITE"); + label422.setStyle("-fx-background-color: WHITE"); + label511.setStyle("-fx-background-color: WHITE"); + label512.setStyle("-fx-background-color: WHITE"); + label521.setStyle("-fx-background-color: WHITE"); + label522.setStyle("-fx-background-color: WHITE"); + label611.setStyle("-fx-background-color: WHITE"); + label612.setStyle("-fx-background-color: WHITE"); + label621.setStyle("-fx-background-color: WHITE"); + label622.setStyle("-fx-background-color: WHITE"); + } +} diff --git a/AutomataGUIDemo/src/main/java/sample/Main.java b/AutomataGUIDemo/src/main/java/sample/Main.java new file mode 100644 index 0000000..42f1e02 --- /dev/null +++ b/AutomataGUIDemo/src/main/java/sample/Main.java @@ -0,0 +1,21 @@ +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.setScene(new Scene(root)); + primaryStage.show(); + } + + public static void main(String[] args) { + launch(args); + } +} diff --git a/AutomataGUIDemo/src/main/resources/icon8.png b/AutomataGUIDemo/src/main/resources/icon8.png new file mode 100644 index 0000000..5f9f24b Binary files /dev/null and b/AutomataGUIDemo/src/main/resources/icon8.png differ diff --git a/AutomataGUIDemo/src/main/resources/onoff.png b/AutomataGUIDemo/src/main/resources/onoff.png new file mode 100644 index 0000000..816db28 Binary files /dev/null and b/AutomataGUIDemo/src/main/resources/onoff.png differ diff --git a/AutomataGUIDemo/src/main/resources/sample.fxml b/AutomataGUIDemo/src/main/resources/sample.fxml new file mode 100644 index 0000000..e39aa35 --- /dev/null +++ b/AutomataGUIDemo/src/main/resources/sample.fxml @@ -0,0 +1,435 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutomataGUIDemo/src/main/resources/top2.jpg b/AutomataGUIDemo/src/main/resources/top2.jpg new file mode 100644 index 0000000..879b1a5 Binary files /dev/null and b/AutomataGUIDemo/src/main/resources/top2.jpg differ diff --git a/AutomataGUIDemo/src/test/java/AutomataTest.java b/AutomataGUIDemo/src/test/java/AutomataTest.java new file mode 100644 index 0000000..a461320 --- /dev/null +++ b/AutomataGUIDemo/src/test/java/AutomataTest.java @@ -0,0 +1,193 @@ +import AutomataDemo.Automata; +import AutomataDemo.STATES; +import org.json.JSONException; +import java.io.IOException; + +import static org.junit.Assert.*; + +public class AutomataTest { + + @org.junit.Test + public void on() throws IOException, JSONException { + Automata a = new Automata(); + a.on(); + assertEquals(a.getState(), STATES.ON); + + a.getMenu(); + a.on(); + assertEquals(a.getState(), STATES.WAIT); + + a.coin(100); + a.on(); + assertEquals(a.getState(), STATES.ACCEPT); + + a.choice("Каппучино"); + a.on(); + assertEquals(a.getState(), STATES.WAIT); + + Float balance = a.getCash(); + boolean result = balance.equals(0.0f); + assertEquals(result, true); + + } + + @org.junit.Test + public void coin() throws IOException, JSONException { + + Automata a = new Automata(); + //state = OFF + a.coin(100); + assertEquals(a.getState(), STATES.OFF); + Float balance = a.getCash(); + assertEquals(balance.equals(0.0f), true); + + a.on(); + a.coin(100); + assertEquals(a.getState(), STATES.ON); + balance = a.getCash(); + assertEquals(balance.equals(0.0f), true); + + a.getMenu(); + + a.coin(100); + assertEquals(a.getState(), STATES.ACCEPT); + balance = a.getCash(); + assertEquals(balance.equals(100.0f), true); + + a.coin(100); + balance = a.getCash(); + assertEquals(balance.equals(200.0f), true); + assertEquals(a.getState(), STATES.ACCEPT); + + } + + @org.junit.Test + public void choice() throws IOException, JSONException { + Automata a = new Automata(); + + a.choice("Каппучино"); + assertEquals(a.getState(), STATES.OFF); + Float balance = a.getCash(); + assertEquals(balance.equals(0.0f), true); + + a.on(); + a.choice("Каппучино"); + assertEquals(a.getState(), STATES.ON); + balance = a.getCash(); + assertEquals(balance.equals(0.0f), true); + + a.getMenu(); + a.choice("Каппучино"); + assertEquals(a.getState(), STATES.WAIT); + balance = a.getCash(); + assertEquals(balance.equals(0.0f), true); + + a.coin(100); + assertEquals(a.getState(), STATES.ACCEPT); + balance = a.getCash(); + assertEquals(balance.equals(100.0f), true); + a.choice("Каппучино"); + assertEquals(a.getState(), STATES.WAIT); + balance = a.getCash(); + assertEquals(balance.equals(0.0f), true); + + + a.coin(90); + assertEquals(a.getState(), STATES.ACCEPT); + balance = a.getCash(); + assertEquals(balance.equals(90.0f), true); + a.choice("Каппучино"); + balance = a.getCash(); + assertEquals(balance.equals(90.0f), true); + assertEquals(a.getState(), STATES.ACCEPT); + a.cancel(); + + a.coin(120); + assertEquals(a.getState(), STATES.ACCEPT); + balance = a.getCash(); + assertEquals(balance.equals(120.0f), true); + a.choice("Каппучино"); + assertEquals(a.getState(), STATES.ACCEPT); + balance = a.getCash(); + assertEquals(balance.equals(20.0f), true); + + } + + @org.junit.Test + public void off() throws IOException, JSONException { + Automata a = new Automata(); + + a.on(); + assertEquals(a.getState(), STATES.ON); + a.off(); + assertEquals(a.getState(), STATES.OFF); + + a.on(); + a.getMenu(); + assertEquals(a.getState(), STATES.WAIT); + a.off(); + assertEquals(a.getState(), STATES.OFF); + + a.on(); + a.getMenu(); + a.coin(100); + assertEquals(a.getState(), STATES.ACCEPT); + Float balance = a.getCash(); + assertEquals(balance.equals(100.0f), true); + + a.off(); + assertEquals(a.getState(), STATES.OFF); + balance = a.getCash(); + assertEquals(balance.equals(0.0f), true); + + } + + @org.junit.Test + public void getMenu() throws IOException, JSONException { + Automata a = new Automata(); + a.getMenu(); + assertEquals(a.getState(), STATES.OFF); + + a.on(); + a.getMenu(); + assertEquals(a.getState(), STATES.WAIT); + + a.coin(100); + a.getMenu(); + assertEquals(a.getState(), STATES.ACCEPT); + + a.choice("Каппучино"); + a.getMenu(); + assertEquals(a.getState(), STATES.WAIT); + + } + + @org.junit.Test + public void cancel() throws IOException, JSONException { + + Automata a = new Automata(); + a.cancel(); + assertEquals(a.getState(), STATES.OFF); + + a.on(); + a.cancel(); + assertEquals(a.getState(), STATES.ON); + + a.getMenu(); + assertEquals(a.getState(), STATES.WAIT); + a.cancel(); + assertEquals(a.getState(), STATES.ON); + + a.getMenu(); + a.coin(50); + assertEquals(a.getState(), STATES.ACCEPT); + Float balance = a.getCash(); + assertEquals(balance.equals(50.0f), true); + a.cancel(); + assertEquals(a.getState(), STATES.WAIT); + balance = a.getCash(); + assertEquals(balance.equals(0.0f), true); + + + } +} \ No newline at end of file diff --git a/AutomataGUIDemo/target/classes/AutomataDemo/Automata.class b/AutomataGUIDemo/target/classes/AutomataDemo/Automata.class new file mode 100644 index 0000000..27d5268 Binary files /dev/null and b/AutomataGUIDemo/target/classes/AutomataDemo/Automata.class differ diff --git a/AutomataGUIDemo/target/classes/AutomataDemo/STATES.class b/AutomataGUIDemo/target/classes/AutomataDemo/STATES.class new file mode 100644 index 0000000..34d66b3 Binary files /dev/null and b/AutomataGUIDemo/target/classes/AutomataDemo/STATES.class differ diff --git a/AutomataGUIDemo/target/classes/icon8.png b/AutomataGUIDemo/target/classes/icon8.png new file mode 100644 index 0000000..5f9f24b Binary files /dev/null and b/AutomataGUIDemo/target/classes/icon8.png differ diff --git a/AutomataGUIDemo/target/classes/onoff.png b/AutomataGUIDemo/target/classes/onoff.png new file mode 100644 index 0000000..816db28 Binary files /dev/null and b/AutomataGUIDemo/target/classes/onoff.png differ diff --git a/AutomataGUIDemo/target/classes/sample.fxml b/AutomataGUIDemo/target/classes/sample.fxml new file mode 100644 index 0000000..e39aa35 --- /dev/null +++ b/AutomataGUIDemo/target/classes/sample.fxml @@ -0,0 +1,435 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutomataGUIDemo/target/classes/sample/Controller.class b/AutomataGUIDemo/target/classes/sample/Controller.class new file mode 100644 index 0000000..341fef6 Binary files /dev/null and b/AutomataGUIDemo/target/classes/sample/Controller.class differ diff --git a/AutomataGUIDemo/target/classes/sample/CookTask.class b/AutomataGUIDemo/target/classes/sample/CookTask.class new file mode 100644 index 0000000..a02a676 Binary files /dev/null and b/AutomataGUIDemo/target/classes/sample/CookTask.class differ diff --git a/AutomataGUIDemo/target/classes/sample/Main.class b/AutomataGUIDemo/target/classes/sample/Main.class new file mode 100644 index 0000000..da8b535 Binary files /dev/null and b/AutomataGUIDemo/target/classes/sample/Main.class differ diff --git a/AutomataGUIDemo/target/classes/top2.jpg b/AutomataGUIDemo/target/classes/top2.jpg new file mode 100644 index 0000000..879b1a5 Binary files /dev/null and b/AutomataGUIDemo/target/classes/top2.jpg differ diff --git a/AutomataGUIDemo/target/test-classes/AutomataTest.class b/AutomataGUIDemo/target/test-classes/AutomataTest.class new file mode 100644 index 0000000..0b91f33 Binary files /dev/null and b/AutomataGUIDemo/target/test-classes/AutomataTest.class differ diff --git a/Clock/.idea/artifacts/Clock_jar.xml b/Clock/.idea/artifacts/Clock_jar.xml new file mode 100644 index 0000000..bde249d --- /dev/null +++ b/Clock/.idea/artifacts/Clock_jar.xml @@ -0,0 +1,11 @@ + + + $PROJECT_DIR$/out/artifacts/Clock_jar + + + + + + + + \ No newline at end of file diff --git a/Clock/.idea/compiler.xml b/Clock/.idea/compiler.xml new file mode 100644 index 0000000..a0b5744 --- /dev/null +++ b/Clock/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Clock/.idea/encodings.xml b/Clock/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/Clock/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Clock/.idea/misc.xml b/Clock/.idea/misc.xml new file mode 100644 index 0000000..4b661a5 --- /dev/null +++ b/Clock/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Clock/.idea/workspace.xml b/Clock/.idea/workspace.xml new file mode 100644 index 0000000..1b34919 --- /dev/null +++ b/Clock/.idea/workspace.xml @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1593589662013 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Clock/Clock.iml b/Clock/Clock.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/Clock/Clock.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/Clock/META-INF/MANIFEST.MF b/Clock/META-INF/MANIFEST.MF new file mode 100644 index 0000000..83187c5 --- /dev/null +++ b/Clock/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Clock + diff --git a/Clock/out/artifacts/Clock_jar/Clock.jar b/Clock/out/artifacts/Clock_jar/Clock.jar new file mode 100644 index 0000000..ae52015 Binary files /dev/null and b/Clock/out/artifacts/Clock_jar/Clock.jar differ diff --git a/Clock/pom.xml b/Clock/pom.xml new file mode 100644 index 0000000..d088a91 --- /dev/null +++ b/Clock/pom.xml @@ -0,0 +1,12 @@ + + + 4.0.0 + + org.example + Clock + 1.0-SNAPSHOT + + + \ No newline at end of file diff --git a/Clock/src/main/java/Clock.java b/Clock/src/main/java/Clock.java new file mode 100644 index 0000000..0abe768 --- /dev/null +++ b/Clock/src/main/java/Clock.java @@ -0,0 +1,102 @@ + + +import javafx.animation.*; +import javafx.application.Application; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.paint.Color; +import javafx.scene.shape.Circle; +import javafx.scene.shape.Line; +import javafx.scene.transform.Rotate; +import javafx.stage.Stage; +import javafx.scene.Scene; +import javafx.scene.Group; +import javafx.util.Duration; + + +import java.net.URL; +import java.util.Calendar; +import java.util.GregorianCalendar; + +public class Clock extends Application { + @Override + public void start(Stage stage) { + + URL path = getClass().getResource("map.jpg"); + + Image image = new Image(path.toString(), 720, 720, false, false); + + ImageView imageView = new ImageView(image); + Calendar calendar = GregorianCalendar.getInstance(); + Circle face = new Circle (357,357,10); + + Line secondHand = new Line(0, 60, 0, -290); + secondHand.setTranslateX(357); secondHand.setTranslateY(357); secondHand.setStroke(Color.BLACK); secondHand.setStrokeWidth(2); + Line minuteHand = new Line(0, 0, 0, -270); + minuteHand.setTranslateX(357); minuteHand.setTranslateY(357); minuteHand.setStroke(Color.BLACK); minuteHand.setStrokeWidth(4); + Line hourHand = new Line(0, 0, 0, -150); + hourHand.setTranslateX(357); hourHand.setTranslateY(357); hourHand.setStroke(Color.BLACK); hourHand.setStrokeWidth(10); + + double seedSecondDegrees = calendar.get(Calendar.SECOND) * (360 / 60); + double seedMinuteDegrees = (calendar.get(Calendar.MINUTE) + seedSecondDegrees / 360.0) * (360 / 60); + double seedHourDegrees = (calendar.get(Calendar.HOUR) + seedMinuteDegrees / 360.0) * (360 / 12) ; + + Rotate secondRotate = new Rotate(seedSecondDegrees); + Rotate minuteRotate = new Rotate(seedMinuteDegrees); + Rotate hourRotate = new Rotate(seedHourDegrees); + + secondHand.getTransforms().add(secondRotate); + minuteHand.getTransforms().add(minuteRotate); + hourHand.getTransforms().add(hourRotate); + + final Timeline secondTime = new Timeline( + + new KeyFrame( + Duration.seconds(60), + new KeyValue( + secondRotate.angleProperty(), + 360 + seedSecondDegrees, + Interpolator.LINEAR + ) + ) + ); + final Timeline minuteTime = new Timeline( + new KeyFrame( + Duration.minutes(60), + new KeyValue( + minuteRotate.angleProperty(), + 360 + seedMinuteDegrees, + Interpolator.LINEAR + ) + ) + ); + Timeline hourTime = new Timeline( + new KeyFrame( + Duration.hours(12), + new KeyValue( + hourRotate.angleProperty(), + 360 + seedHourDegrees, + Interpolator.LINEAR + ) + ) + ); + + secondTime.setCycleCount(Animation.INDEFINITE); + minuteTime.setCycleCount(Animation.INDEFINITE); + hourTime.setCycleCount(Animation.INDEFINITE); + + secondTime.play(); + minuteTime.play(); + hourTime.play(); + + Group root = new Group(imageView, hourHand, minuteHand, secondHand, face); + Scene scene = new Scene(root, 720,720); + + stage.setScene(scene); + stage.show(); + + } + public static void main(String args[]) { + launch(args); + } +} \ No newline at end of file diff --git a/Clock/src/main/resources/14.jpg b/Clock/src/main/resources/14.jpg new file mode 100644 index 0000000..4e08980 Binary files /dev/null and b/Clock/src/main/resources/14.jpg differ diff --git a/Clock/src/main/resources/3.jpg b/Clock/src/main/resources/3.jpg new file mode 100644 index 0000000..209d52b Binary files /dev/null and b/Clock/src/main/resources/3.jpg differ diff --git a/Clock/src/main/resources/clock.jpg b/Clock/src/main/resources/clock.jpg new file mode 100644 index 0000000..3664773 Binary files /dev/null and b/Clock/src/main/resources/clock.jpg differ diff --git a/Clock/src/main/resources/map.jpg b/Clock/src/main/resources/map.jpg new file mode 100644 index 0000000..46083ec Binary files /dev/null and b/Clock/src/main/resources/map.jpg differ diff --git a/Clock/src/main/resources/map1.jpg b/Clock/src/main/resources/map1.jpg new file mode 100644 index 0000000..3eb1940 Binary files /dev/null and b/Clock/src/main/resources/map1.jpg differ diff --git a/Clock/target/classes/14.jpg b/Clock/target/classes/14.jpg new file mode 100644 index 0000000..4e08980 Binary files /dev/null and b/Clock/target/classes/14.jpg differ diff --git a/Clock/target/classes/3.jpg b/Clock/target/classes/3.jpg new file mode 100644 index 0000000..209d52b Binary files /dev/null and b/Clock/target/classes/3.jpg differ diff --git a/Clock/target/classes/Clock.class b/Clock/target/classes/Clock.class new file mode 100644 index 0000000..8994f98 Binary files /dev/null and b/Clock/target/classes/Clock.class differ diff --git a/Clock/target/classes/META-INF/Clock.kotlin_module b/Clock/target/classes/META-INF/Clock.kotlin_module new file mode 100644 index 0000000..a49347a Binary files /dev/null and b/Clock/target/classes/META-INF/Clock.kotlin_module differ diff --git a/Clock/target/classes/clock.jpg b/Clock/target/classes/clock.jpg new file mode 100644 index 0000000..3664773 Binary files /dev/null and b/Clock/target/classes/clock.jpg differ diff --git a/Clock/target/classes/map.jpg b/Clock/target/classes/map.jpg new file mode 100644 index 0000000..46083ec Binary files /dev/null and b/Clock/target/classes/map.jpg differ diff --git a/Clock/target/classes/map1.jpg b/Clock/target/classes/map1.jpg new file mode 100644 index 0000000..3eb1940 Binary files /dev/null and b/Clock/target/classes/map1.jpg differ diff --git a/README.md b/README.md deleted file mode 100644 index 7da042c..0000000 --- a/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# Java-lab-5 -# Лабораторная работа №5 (AutomataGUI и ClockDemo) - -## Задачи - -Описание задач находится [здесь](http://shtanyuk.tk/edu/nniit/java-new/labs/labs5.html) - -## Алгоритм выполнения работы - -Для выполнения работы необходимо: -1. Выполнить *fork* репозитария в свой аккаунт. -1. Выполнить клонирование репозитария из своего аккаунта к себе на локальную машину (`git clone`). -1. Создать ветку **git** с индивидуальным номером (`git branch имя`). -1. Сделать ветку активной (`git checkout имя`). -1. Создать каталог *work*. -1. Поместить в этот каталог файлы с расширением *.java*. -1. Добавить файлы в хранилище (`git add`). -1. Выполнить фиксацию изменений (`git commit -m "комментарий"`). -1. Отправить содержимое ветки в свой удаленный репозитарий (`git push origin имя`). -1. Создать пул-запрос в репозитарий группы и ждать результата... - -## Список участников/веток - -| ФИО | Имя ветки | -|-------------------|-----------|