diff --git a/AutomataGUI/.idea/.gitignore b/AutomataGUI/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/AutomataGUI/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/AutomataGUI/.idea/artifacts/AutomataGUI_jar.xml b/AutomataGUI/.idea/artifacts/AutomataGUI_jar.xml new file mode 100644 index 0000000..f9e5854 --- /dev/null +++ b/AutomataGUI/.idea/artifacts/AutomataGUI_jar.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/out/artifacts/AutomataGUI_jar + + + + + \ No newline at end of file diff --git a/AutomataGUI/.idea/compiler.xml b/AutomataGUI/.idea/compiler.xml new file mode 100644 index 0000000..217af47 --- /dev/null +++ b/AutomataGUI/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/AutomataGUI/.idea/description.html b/AutomataGUI/.idea/description.html new file mode 100644 index 0000000..cc10d56 --- /dev/null +++ b/AutomataGUI/.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/AutomataGUI/.idea/encodings.xml b/AutomataGUI/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/AutomataGUI/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/AutomataGUI/.idea/gradle.xml b/AutomataGUI/.idea/gradle.xml new file mode 100644 index 0000000..3e3960b --- /dev/null +++ b/AutomataGUI/.idea/gradle.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/AutomataGUI/.idea/misc.xml b/AutomataGUI/.idea/misc.xml new file mode 100644 index 0000000..4e6e724 --- /dev/null +++ b/AutomataGUI/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/AutomataGUI/.idea/modules.xml b/AutomataGUI/.idea/modules.xml new file mode 100644 index 0000000..6887be2 --- /dev/null +++ b/AutomataGUI/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/AutomataGUI/.idea/uiDesigner.xml b/AutomataGUI/.idea/uiDesigner.xml new file mode 100644 index 0000000..3b00020 --- /dev/null +++ b/AutomataGUI/.idea/uiDesigner.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AutomataGUI/.idea/vcs.xml b/AutomataGUI/.idea/vcs.xml new file mode 100644 index 0000000..def6a6a --- /dev/null +++ b/AutomataGUI/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/AutomataGUI/AutomataGUI.iml b/AutomataGUI/AutomataGUI.iml new file mode 100644 index 0000000..5925121 --- /dev/null +++ b/AutomataGUI/AutomataGUI.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/AutomataGUI/AutomataGUI.jar b/AutomataGUI/AutomataGUI.jar new file mode 100644 index 0000000..f4c915f Binary files /dev/null and b/AutomataGUI/AutomataGUI.jar differ diff --git a/AutomataGUI/src/META-INF/MANIFEST.MF b/AutomataGUI/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..440fa71 --- /dev/null +++ b/AutomataGUI/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: sample.Main + diff --git a/AutomataGUI/src/sample/Automata.java b/AutomataGUI/src/sample/Automata.java new file mode 100644 index 0000000..472f86b --- /dev/null +++ b/AutomataGUI/src/sample/Automata.java @@ -0,0 +1,113 @@ +package sample; + +import java.util.ArrayList; +enum States //текущее состояние автомата; +{OFF, WAIT, ACCEPT, CHECK, COOK} + +public class Automata { + private float cash; //текущея сумма + private States state;//начальное состояние + + public Automata() { + this.cash = 0; + this.state = States.OFF;//начальное состояние + } + + public States getState() { + return state; + } + + public void on() { // включение автомата; + if (state == States.OFF ) { + state = States.WAIT; + } + } + + public void off() { //выключение автомата; + if (state == States.WAIT ) { + state = States.OFF; + } + } + + public ArrayList[] getMenu() { // отображение меню с напитками и ценами для пользователя; + ArrayList menuItem = new ArrayList(); + ArrayList menuItemPrice = new ArrayList(); + menuItem.add("Espresso"); + menuItemPrice.add(35f); + menuItem.add("Cappuccino"); + menuItemPrice.add(45f); + menuItem.add("Green Tea"); + menuItemPrice.add(15f); + menuItem.add("Black Tea"); + menuItemPrice.add(15f); + menuItem.add("Hot Chocolate"); + menuItemPrice.add(30f); + menuItem.add("Orange juice"); + menuItemPrice.add(60f); + ArrayList[] fullMenu = {menuItem, menuItemPrice}; + return fullMenu; + } + + public void coin( float money ) { //занесение денег на счёт пользователем; + if(state == States.WAIT || state == States.ACCEPT){ + state = States.ACCEPT; + cash += money; + } + } + + public float getCash() { // геттер к закрытой переменной cash + return cash; + } + + private boolean check(float price) { // проверка наличия необходимой суммы; + return (state == States.CHECK) && (cash >= price); + } + + public float cancel() { // отмена сеанса обслуживания пользователем; + float change = 0; + if (state == States.CHECK || state == States.ACCEPT){ + state = States.WAIT; + change = cash; + cash = 0; + } + return change; + } + private void cook(int itemNumber) { // имитация процесса приготовления напитка; + if ( state == States.CHECK){ + state = States.COOK; + } + } + + private void finish() { // завершение обслуживания пользователя. + if (state == States.COOK) { + state = States.WAIT; + System.out.println("Take your drink, man"); + } + } + + public float choice (int itemNumber) { // выбор напитка пользователем; + float change = 0; + try { + if (state == States.ACCEPT) { + state = States.CHECK; + ArrayList[] menu = getMenu(); + float price = (Float) menu[1].get(itemNumber); + if (check(price)) { + change = cash -= price; + cash = 0; + cook(itemNumber); + finish(); + } + else { + change = cancel(); + } + } + } + catch (IndexOutOfBoundsException e1){ + System.out.println("I don't cook this, try again! " + e1); + change = cancel(); + System.out.println("Take the change: " + change); + } + return change; + } +} \ No newline at end of file diff --git a/AutomataGUI/src/sample/Controller.java b/AutomataGUI/src/sample/Controller.java new file mode 100644 index 0000000..b6f82a8 --- /dev/null +++ b/AutomataGUI/src/sample/Controller.java @@ -0,0 +1,157 @@ +package sample; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; + +import java.util.ArrayList; + +public class Controller { + Automata CoffeeMashine = new Automata(); + + //Button + @FXML + private Button btnOnOff; + @FXML + private Button btnOkMoney; + @FXML + private Button btnChange; + @FXML + private Button btnMenu1; + @FXML + private Button btnMenu2; + @FXML + private Button btnMenu3; + @FXML + private Button btnMenu4; + @FXML + private Button btnMenu5; + @FXML + private Button btnMenu6; + + //Label + @FXML + private Label lbMenu1; + @FXML + private Label lbMenu2; + @FXML + private Label lbMenu3; + @FXML + private Label lbMenu4; + @FXML + private Label lbMenu5; + @FXML + private Label lbMenu6; + + //Text Field + @FXML + private TextField tfDisplay; + @FXML + private TextField tfMoney; + @FXML + private TextField tfChange; + + private ArrayList[] menu; + public void onAction_btnOnOff (ActionEvent actionEvent) { + if (CoffeeMashine.getState() == States.OFF ) { + CoffeeMashine.on(); + tfDisplay.setText("CoffeeMaker ON! Make your choice, man"); + tfMoney.editableProperty().setValue(true); + tfChange.editableProperty().setValue(true); + btnMenu1.setDisable(false); + btnMenu2.setDisable(false); + btnMenu3.setDisable(false); + btnMenu4.setDisable(false); + btnMenu5.setDisable(false); + btnMenu6.setDisable(false); + btnChange.setDisable(false); + btnOkMoney.setDisable(false); + menu = CoffeeMashine.getMenu(); + btnMenu1.setText(menu[0].get(0).toString()); + btnMenu2.setText(menu[0].get(1).toString()); + btnMenu3.setText(menu[0].get(2).toString()); + btnMenu4.setText(menu[0].get(3).toString()); + btnMenu5.setText(menu[0].get(4).toString()); + btnMenu6.setText(menu[0].get(5).toString()); + lbMenu1.setText(menu[1].get(0).toString()); + lbMenu2.setText(menu[1].get(1).toString()); + lbMenu3.setText(menu[1].get(2).toString()); + lbMenu4.setText(menu[1].get(3).toString()); + lbMenu5.setText(menu[1].get(4).toString()); + lbMenu6.setText(menu[1].get(5).toString()); + } + else if (CoffeeMashine.getState() == States.WAIT ) { + tfDisplay.setText("Goodbye"); + tfMoney.editableProperty().setValue(false); + tfChange.editableProperty().setValue(false); + btnMenu1.setDisable(true); + btnMenu2.setDisable(true); + btnMenu3.setDisable(true); + btnMenu4.setDisable(true); + btnMenu5.setDisable(true); + btnMenu6.setDisable(true); + btnChange.setDisable(true); + btnOkMoney.setDisable(true); + btnMenu1.setText(""); + btnMenu2.setText(""); + btnMenu3.setText(""); + btnMenu4.setText(""); + btnMenu5.setText(""); + btnMenu6.setText(""); + lbMenu1.setText(""); + lbMenu2.setText(""); + lbMenu3.setText(""); + lbMenu4.setText(""); + lbMenu5.setText(""); + lbMenu6.setText(""); + CoffeeMashine.off(); + } + } + + public void onAction_btnOkMoney (ActionEvent actionEvent) { + if (CoffeeMashine.getState() != States.OFF ) { + float temp = Float.parseFloat(tfMoney.getText()); + tfMoney.setText(""); + CoffeeMashine.coin(temp); + tfDisplay.setText("Credit: " + CoffeeMashine.getCash()); + } + } + + public void onAction_btnChange (ActionEvent actionEvent){ + Float temp = CoffeeMashine.cancel(); + if (temp != 0) { + tfDisplay.setText("Choose!"); + tfChange.setText(temp.toString() ); + } + else { + tfChange.setText(""); + tfDisplay.setText("Your coins 0"); + } + } + + public void onAction_btnMenu (ActionEvent actionEvent){ + int temp = 0; + if(actionEvent.getSource() == btnMenu1){temp = 0;} + if(actionEvent.getSource() == btnMenu2){temp = 1;} + if(actionEvent.getSource() == btnMenu3){temp = 2;} + if(actionEvent.getSource() == btnMenu4){temp = 3;} + if(actionEvent.getSource() == btnMenu5){temp = 4;} + if(actionEvent.getSource() == btnMenu5){temp = 5;} + float cash = CoffeeMashine.getCash(); + float change = CoffeeMashine.choice(temp); + if (change != cash){ + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + tfDisplay.setText("Take your "+menu[0].get(temp)); + } + else {tfDisplay.setText("Take your coins and try again" );} + if (change != 0) {tfChange.setText("" + change);} + else {tfChange.setText("");} + + } +} diff --git a/AutomataGUI/src/sample/Main.java b/AutomataGUI/src/sample/Main.java new file mode 100644 index 0000000..f7ff575 --- /dev/null +++ b/AutomataGUI/src/sample/Main.java @@ -0,0 +1,33 @@ +package sample; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.media.Media; +import javafx.scene.media.MediaPlayer; +import javafx.stage.Stage; + +import java.net.URL; + + +public class Main extends Application { + + @Override + public void start(Stage primaryStage) throws Exception{ + Parent root = FXMLLoader.load(getClass().getResource("sample.fxml")); + primaryStage.setTitle("CoffeeMaker"); + primaryStage.setScene(new Scene(root, 700, 700)); + primaryStage.setResizable(false); + primaryStage.show(); + + URL resource = Main.class.getResource("/321.mp3"); + Media media = new Media(resource.toString()); + MediaPlayer mediaPlayer = new MediaPlayer(media); + mediaPlayer.play(); + } + + public static void main(String[] args) { + launch(args); + } +} diff --git a/AutomataGUI/src/sample/sample.fxml b/AutomataGUI/src/sample/sample.fxml new file mode 100644 index 0000000..181114f --- /dev/null +++ b/AutomataGUI/src/sample/sample.fxml @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ClockWatch/.idea/.gitignore b/ClockWatch/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/ClockWatch/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/ClockWatch/.idea/artifacts/ClockWatch_jar.xml b/ClockWatch/.idea/artifacts/ClockWatch_jar.xml new file mode 100644 index 0000000..cb05b37 --- /dev/null +++ b/ClockWatch/.idea/artifacts/ClockWatch_jar.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/out/artifacts/ClockWatch_jar + + + + + \ No newline at end of file diff --git a/ClockWatch/.idea/compiler.xml b/ClockWatch/.idea/compiler.xml new file mode 100644 index 0000000..217af47 --- /dev/null +++ b/ClockWatch/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/ClockWatch/.idea/description.html b/ClockWatch/.idea/description.html new file mode 100644 index 0000000..cc10d56 --- /dev/null +++ b/ClockWatch/.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/ClockWatch/.idea/encodings.xml b/ClockWatch/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/ClockWatch/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ClockWatch/.idea/gradle.xml b/ClockWatch/.idea/gradle.xml new file mode 100644 index 0000000..3e3960b --- /dev/null +++ b/ClockWatch/.idea/gradle.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ClockWatch/.idea/misc.xml b/ClockWatch/.idea/misc.xml new file mode 100644 index 0000000..4e6e724 --- /dev/null +++ b/ClockWatch/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/ClockWatch/.idea/modules.xml b/ClockWatch/.idea/modules.xml new file mode 100644 index 0000000..b56dd4c --- /dev/null +++ b/ClockWatch/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ClockWatch/.idea/uiDesigner.xml b/ClockWatch/.idea/uiDesigner.xml new file mode 100644 index 0000000..3b00020 --- /dev/null +++ b/ClockWatch/.idea/uiDesigner.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ClockWatch/.idea/vcs.xml b/ClockWatch/.idea/vcs.xml new file mode 100644 index 0000000..def6a6a --- /dev/null +++ b/ClockWatch/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ClockWatch/ClockWatch.iml b/ClockWatch/ClockWatch.iml new file mode 100644 index 0000000..5925121 --- /dev/null +++ b/ClockWatch/ClockWatch.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/ClockWatch/ClockWatch.jar b/ClockWatch/ClockWatch.jar new file mode 100644 index 0000000..b6d1d2c Binary files /dev/null and b/ClockWatch/ClockWatch.jar differ diff --git a/ClockWatch/resource/341.mp3 b/ClockWatch/resource/341.mp3 new file mode 100644 index 0000000..e3b80df Binary files /dev/null and b/ClockWatch/resource/341.mp3 differ diff --git a/ClockWatch/resource/567.png b/ClockWatch/resource/567.png new file mode 100644 index 0000000..8b4f220 Binary files /dev/null and b/ClockWatch/resource/567.png differ diff --git a/ClockWatch/src/META-INF/MANIFEST.MF b/ClockWatch/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..97db64c --- /dev/null +++ b/ClockWatch/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: sample.ClockWatch + diff --git a/ClockWatch/src/sample/ClockWatch.java b/ClockWatch/src/sample/ClockWatch.java new file mode 100644 index 0000000..ed3f696 --- /dev/null +++ b/ClockWatch/src/sample/ClockWatch.java @@ -0,0 +1,122 @@ +package sample; + +import javafx.animation.*; +import javafx.application.Application; +import javafx.scene.Group; +import javafx.scene.Scene; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.media.Media; +import javafx.scene.media.MediaPlayer; +import javafx.scene.paint.Color; +import javafx.scene.shape.Circle; +import javafx.scene.shape.Line; +import javafx.scene.shape.StrokeLineCap; +import javafx.scene.transform.Rotate; +import javafx.stage.Stage; +import javafx.util.Duration; +import java.net.URL; +import java.util.Calendar; +import java.util.GregorianCalendar; + +public class ClockWatch extends Application{ + @Override + public void start(Stage stage) throws Exception { + + Image image = new Image("/567.png", 580, 580, false, false); + ImageView imageView = new ImageView(image); + Calendar calendar = GregorianCalendar.getInstance(); + + URL resource = ClockWatch.class.getResource("/341.mp3"); + Media media = new Media(resource.toString()); + MediaPlayer mediaPlayer = new MediaPlayer(media); + mediaPlayer.play(); + + Circle face = new Circle(295,295,8); + face.setFill(Color.BLACK); + + Line secondHand = new Line(0,35,0,-190); + secondHand.setTranslateX(295); + secondHand.setTranslateY(295); + secondHand.setStroke(Color.PURPLE); + secondHand.setStrokeWidth(5); + secondHand.setStrokeLineCap(StrokeLineCap.ROUND); + + Line minuteHand = new Line(0,0,0,-175); + minuteHand.setTranslateX(295); + minuteHand.setTranslateY(295); + minuteHand.setStroke(Color.PURPLE); + minuteHand.setStrokeWidth(8); + minuteHand.setStrokeLineCap(StrokeLineCap.ROUND); + + Line hourHand = new Line(0,0,0,-150); + hourHand.setTranslateX(295); + hourHand.setTranslateY(295); + hourHand.setStroke(Color.PURPLE); + hourHand.setStrokeWidth(11); + hourHand.setStrokeLineCap(StrokeLineCap.ROUND); + + 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, 580,580); + + stage.setScene(scene); + stage.show(); + } + + public static void main(String[] args) { + launch(args); + } +} \ No newline at end of file diff --git a/ClockWatch/src/sample/sample.fxml b/ClockWatch/src/sample/sample.fxml new file mode 100644 index 0000000..363237a --- /dev/null +++ b/ClockWatch/src/sample/sample.fxml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file