diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..c96c3b6 Binary files /dev/null and b/.DS_Store differ diff --git a/Clock.java b/Clock.java new file mode 100644 index 0000000..eae2fab --- /dev/null +++ b/Clock.java @@ -0,0 +1,109 @@ +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.paint.Color; +import javafx.scene.shape.Circle; +import javafx.scene.shape.Line; +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 Clock extends Application { + @Override + public void start(Stage stage) throws Exception { + stage.setTitle("Clock"); + URL background = getClass().getResource("/image.png"); + Image cl = new Image(background.toString(), 600, 600, false, false); + ImageView imageView = new ImageView(cl); + Calendar calendar = GregorianCalendar.getInstance(); + Circle face = new Circle(300,300,10); + Circle face2 = new Circle(300,300,280); + face.setFill(Color.WHITE); + face2.setFill(null); + face2.setStroke(Color.WHITE); + face2.setStrokeWidth(6); + + Line secondArrow = new Line(0,60,0,-290); + secondArrow.setTranslateX(300); + secondArrow.setTranslateY(300); + secondArrow.setStroke(Color.WHITE); + secondArrow.setStrokeWidth(2); + Line minuteArrow = new Line(0,60,0,-250); + minuteArrow.setTranslateX(300); + minuteArrow.setTranslateY(300); + minuteArrow.setStroke(Color.WHITE); + minuteArrow.setStrokeWidth(6); + Line hourArrow = new Line(0,60,0,-150); + hourArrow.setTranslateX(300); + hourArrow.setTranslateY(300); + hourArrow.setStroke(Color.WHITE); + hourArrow.setStrokeWidth(8); + + double secDegree = calendar.get(Calendar.SECOND) * (360 / 60); + double minDegree = (calendar.get(Calendar.MINUTE) + secDegree / 360.0) * (360 / 60); + double hourDegree = (calendar.get(Calendar.HOUR) + minDegree / 360) * (360 / 12); + + Rotate rotateSec = new Rotate(secDegree); + Rotate rotateMin = new Rotate(minDegree); + Rotate rotateHour = new Rotate(hourDegree); + + secondArrow.getTransforms().add(rotateSec); + minuteArrow.getTransforms().add(rotateMin); + hourArrow.getTransforms().add(rotateHour); + + final Timeline secTime = new Timeline( + new KeyFrame( + Duration.seconds(60), + new KeyValue( + rotateSec.angleProperty(), + 360 + secDegree, + Interpolator.LINEAR + ) + ) + ); + + final Timeline minTime = new Timeline( + new KeyFrame( + Duration.minutes(60), + new KeyValue( + rotateMin.angleProperty(), + 360 + minDegree, + Interpolator.LINEAR + ) + ) + ); + final Timeline hourTime = new Timeline( + new KeyFrame( + Duration.hours(12), + new KeyValue( + rotateHour.angleProperty(), + 360 + hourDegree, + Interpolator.LINEAR + ) + ) + ); + secTime.setCycleCount(Animation.INDEFINITE); + minTime.setCycleCount(Animation.INDEFINITE); + hourTime.setCycleCount(Animation.INDEFINITE); + + secTime.play(); + minTime.play(); + hourTime.play(); + + Group root = new Group(imageView, face,face2,secondArrow,minuteArrow,hourArrow); + Scene scene = new Scene(root, 600, 600); + stage.setScene(scene); + stage.show(); + + } + public static void main(String[] args) { + Application.launch(args); + } +} diff --git a/ProgectClock.jar b/ProgectClock.jar new file mode 100644 index 0000000..05c9bf3 Binary files /dev/null and b/ProgectClock.jar differ diff --git a/lab5.iml b/lab5.iml new file mode 100644 index 0000000..d6399ac --- /dev/null +++ b/lab5.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..9343ec0 --- /dev/null +++ b/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + niit + lab5 + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 7 + 7 + + + + + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + org.json + json + 20180130 + + + org.decimal4j + decimal4j + 1.0.3 + + + commons-io + commons-io + 2.6 + + + \ No newline at end of file diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..acfa152 Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 0000000..4df2b73 Binary files /dev/null and b/src/main/.DS_Store differ diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store new file mode 100644 index 0000000..7fc251b Binary files /dev/null and b/src/main/java/.DS_Store differ diff --git a/src/main/java/Methods/Automata.java b/src/main/java/Methods/Automata.java new file mode 100644 index 0000000..18f944d --- /dev/null +++ b/src/main/java/Methods/Automata.java @@ -0,0 +1,135 @@ +package Methods; + +import org.apache.commons.io.FileUtils; +import org.json.JSONArray; +import org.json.JSONObject; + + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Paths; +import java.util.*; + +public class Automata { + + private enum States { + OFF, WAIT, ACCEPT, CHECK, COOK + } + + private Integer cash; + private HashMap Menu = new HashMap<>(); + private States state; + + public Automata(String menu) { + cash = 0; + state = States.OFF; + try { + URL resource = getClass().getResource(menu); + File file = Paths.get(resource.toURI()).toFile(); + String content = FileUtils.readFileToString(file, "utf-8"); + JSONArray menu1 = new JSONArray(content); + for (int i = 0;i0) { + state = States.ACCEPT; + cash = cash + coin; + return Integer.toString(cash); + } else return "Операция невозможна!"; + } + + + public String getState() { + return state.toString(); + } + private boolean check(Integer price){ + if (cash>= price) + return true; + else + return false; + } + private String cook(){ + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + state = States.COOK; + return state.toString(); + } + public String finish(String surrender){ + if (state == States.WAIT){ + if(surrender.equals("YES")&& cash%5 == 0){ + state = States.WAIT; + int money = cash; + cash = 0; + return "Ваша сдача - "+money; + } + else { + state = States.WAIT; + cash = 0; + return "Благодарим за покупку!"; + } + } + else return "Операция невозможна!"; + } + public String cancel(){ + if (state == States.ACCEPT || state == States.COOK){ + state = States.WAIT; + return state.toString(); + } + else return "Операция невозможна!"; + } + public Integer checkcash (){ + if (state!=States.OFF){ + return cash; + } + else return 0; + } + public String choise(String name){ + if (state == States.ACCEPT||state == States.WAIT){ + if (Menu.containsKey(name)){ + state = States.CHECK; + if(check(Menu.get(name))){ + cash=cash-Menu.get(name); + return cook(); + } + else{ + return "Недостаточно средств на счете!"; + } + } + else{ + return "Выбранного вами напитка не существует"; + } + } + else return "Операция невозможна!"; + } +} \ No newline at end of file diff --git a/src/main/java/sample/Controller.java b/src/main/java/sample/Controller.java new file mode 100644 index 0000000..b13d3b0 --- /dev/null +++ b/src/main/java/sample/Controller.java @@ -0,0 +1,274 @@ +package sample; + +import Methods.Automata; + +import javafx.application.Platform; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.*; + + +import java.net.URL; +import java.util.ResourceBundle; +import java.util.Timer; +import java.util.TimerTask; + + +public class Controller implements Initializable{ + @FXML + private Button btnTeaBlackLemon; + @FXML + private Button btnTeaBlackBerg; + @FXML + private Button btnTeaGreen; + @FXML + private Button btnTeaGreenLemon; + @FXML + private Button btnCapuchino; + @FXML + private Button btnCoffeBlended; + @FXML + private Button btnLatte; + @FXML + private Button btnCoffeBlendedMilk; + + + @FXML + private TextField tfDrink; + @FXML + private TextField tfPrice; + + @FXML + private TextField tfScore; + @FXML + private TextField tfState; + @FXML + private Button btBuy; + + @FXML + private RadioButton rbOn; + @FXML + private RadioButton rbOff; + + private ToggleGroup tgONOFF = new ToggleGroup(); + + @FXML + private TextField tfEntScore; + @FXML + private Button btnEnter; + @FXML + private Button btnCancel; + @FXML + private Button btnFinish; + @FXML + private CheckBox cbSurrender; + + private Automata automata; + private Timer t,t2; + private TimerTask task,task2; + + @Override + public void initialize(URL url, ResourceBundle resourceBundle){ + automata = new Automata("/menu.json"); + rbOff.fire(); + tfState.setText(automata.off()); + btnTeaBlackLemon.setDisable(true); + btnTeaBlackBerg.setDisable(true); + btnTeaGreen.setDisable(true); + btnTeaGreenLemon.setDisable(true); + btnCapuchino.setDisable(true); + btnCoffeBlended.setDisable(true); + btnLatte.setDisable(true); + btnCoffeBlendedMilk.setDisable(true); + tfDrink.setDisable(true); + tfPrice.setDisable(true); + tfScore.setDisable(true); + tfEntScore.setDisable(true); + btnEnter.setDisable(true); + btnCancel.setDisable(true); + btnFinish.setDisable(true); + cbSurrender.setDisable(true); + btBuy.setDisable(true); + + rbOn.setToggleGroup(tgONOFF); + rbOff.setToggleGroup(tgONOFF); + + tgONOFF.selectedToggleProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue changed, Toggle oldValue, Toggle newValue) { + RadioButton selectedBtn = (RadioButton) newValue; + String exptype = selectedBtn.getText(); + if (exptype.equals("on")){ + btnTeaBlackLemon.setDisable(false); + btnTeaBlackBerg.setDisable(false); + btnTeaGreen.setDisable(false); + btnTeaGreenLemon.setDisable(false); + btnCapuchino.setDisable(false); + btnCoffeBlended.setDisable(false); + btnLatte.setDisable(false); + btnCoffeBlendedMilk.setDisable(false); + tfDrink.setDisable(false); + tfPrice.setDisable(false); + tfScore.setDisable(false); + tfEntScore.setDisable(false); + btnEnter.setDisable(false); + btnCancel.setDisable(false); + btnFinish.setDisable(false); + cbSurrender.setDisable(false); + btBuy.setDisable(false); + tfState.setText(automata.on()); + tfScore.setText(automata.checkcash().toString()); + } + else if (exptype.equals("off")){ + tfState.setText(automata.off()); + tfDrink.clear(); + tfPrice.clear(); + tfScore.clear(); + btnTeaBlackLemon.setDisable(true); + btnTeaBlackBerg.setDisable(true); + btnTeaGreen.setDisable(true); + btnTeaGreenLemon.setDisable(true); + btnCapuchino.setDisable(true); + btnCoffeBlended.setDisable(true); + btnLatte.setDisable(true); + btnCoffeBlendedMilk.setDisable(true); + tfDrink.setDisable(true); + tfPrice.setDisable(true); + tfScore.setDisable(true); + tfEntScore.setDisable(true); + btnEnter.setDisable(true); + btnCancel.setDisable(true); + btnFinish.setDisable(true); + cbSurrender.setDisable(false); + btBuy.setDisable(true); + } + } + }); + } + @FXML + public void TeaBlackLemonClick (){ + tfDrink.clear(); + tfPrice.clear(); + String text = btnTeaBlackLemon.getText(); + tfDrink.setText(text); + tfPrice.setText(automata.getPrice(text).toString()); + } + @FXML + public void TeaBlackBergClick (){ + tfDrink.clear(); + tfPrice.clear(); + String text = btnTeaBlackBerg.getText(); + tfDrink.setText(text); + tfPrice.setText(automata.getPrice(text).toString()); + } + @FXML + public void TeaGreenClick (){ + tfDrink.clear(); + tfPrice.clear(); + String text = btnTeaGreen.getText(); + tfDrink.setText(text); + tfPrice.setText(automata.getPrice(text).toString()); + } + @FXML + public void TeaGreenLemonClick (){ + tfDrink.clear(); + tfPrice.clear(); + String text = btnTeaGreenLemon.getText(); + tfDrink.setText(text); + tfPrice.setText(automata.getPrice(text).toString()); + } + @FXML + public void CapuchinoClick (){ + tfDrink.clear(); + tfPrice.clear(); + String text = btnCapuchino.getText(); + tfDrink.setText(text); + tfPrice.setText(automata.getPrice(text).toString()); + } + @FXML + public void CoffeBlendedClick (){ + tfDrink.clear(); + tfPrice.clear(); + String text = btnCoffeBlended.getText(); + tfDrink.setText(text); + tfPrice.setText(automata.getPrice(text).toString()); + } + @FXML + public void LatteClick (){ + tfDrink.clear(); + tfPrice.clear(); + String text = btnLatte.getText(); + tfDrink.setText(text); + tfPrice.setText(automata.getPrice(text).toString()); + } + @FXML + public void CoffeBlendedMilkClick (){ + tfDrink.clear(); + tfPrice.clear(); + String text = btnCoffeBlendedMilk.getText(); + tfDrink.setText(text); + tfPrice.setText(automata.getPrice(text).toString()); + } + @FXML + public void EnterClick(){ + tfScore.setText(automata.coin(Integer.parseInt(tfEntScore.getText()))); + tfEntScore.clear(); + tfState.setText(automata.getState()); + } + @FXML + public void BuyClick() { + btBuy.setDisable(true); + t=new Timer(); + task = new TimerTask() { + @Override public void run() { + Platform.runLater(new Runnable() { + @Override public void run() { + tfState.setText(automata.choise(tfDrink.getText())); + tfScore.setText(automata.checkcash().toString()); + } + }); + } + }; + t.schedule(task,2000); + t2=new Timer(); + task2 = new TimerTask() { + @Override public void run() { + Platform.runLater(new Runnable() { + @Override public void run() { + if(automata.getState().equals("COOK")) + tfState.setText(automata.cancel()); + else + tfState.setText(automata.getState()); + btBuy.setDisable(false); + } + }); + } + }; + t2.schedule(task2,7000); + new Thread(new Runnable() { + @Override public void run() { + Platform.runLater(new Runnable() { + @Override public void run() { + tfState.setText("CHECK"); + } + }); + } + }).start(); + } + @FXML + public void CancelClick(){ + tfState.setText(automata.cancel()); + } + @FXML + public void FinishClick(){ + if (cbSurrender.isSelected()){ + tfState.setText(automata.finish("YES")); + tfScore.setText(automata.checkcash().toString()); + } + else + tfScore.setText(automata.checkcash().toString()); + } +} + diff --git a/src/main/java/sample/Main.java b/src/main/java/sample/Main.java new file mode 100644 index 0000000..c024264 --- /dev/null +++ b/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.setTitle("Automata"); + primaryStage.setScene(new Scene(root)); + primaryStage.show(); + } + public static void main(String[] args) { + launch(args); + } +} diff --git a/src/main/java/sample/sample.fxml b/src/main/java/sample/sample.fxml new file mode 100644 index 0000000..075aae2 --- /dev/null +++ b/src/main/java/sample/sample.fxml @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/.DS_Store b/src/main/resources/.DS_Store new file mode 100644 index 0000000..c2cccd7 Binary files /dev/null and b/src/main/resources/.DS_Store differ diff --git a/src/main/resources/image/.DS_Store b/src/main/resources/image/.DS_Store new file mode 100644 index 0000000..c48de1d Binary files /dev/null and b/src/main/resources/image/.DS_Store differ diff --git a/src/main/resources/image/coffe.png b/src/main/resources/image/coffe.png new file mode 100644 index 0000000..6f88150 Binary files /dev/null and b/src/main/resources/image/coffe.png differ diff --git a/src/main/resources/menu.json b/src/main/resources/menu.json new file mode 100644 index 0000000..eb2fb16 --- /dev/null +++ b/src/main/resources/menu.json @@ -0,0 +1,34 @@ +[ + { + "name": "Чай черный с лимоном", + "price" : 20 + }, + { + "name": "Чай черный с бергамотом", + "price" : 30 + }, + { + "name": "Чай зеленый", + "price" : 20 + }, + { + "name": "Чай зеленый с лимоном", + "price" : 30 + }, + { + "name": "Капучино", + "price" : 45 + }, + { + "name": "Кофе зерновой молотый", + "price" : 35 + }, + { + "name": "Латте", + "price" : 45 + }, + { + "name": "Кофе зерновой с молоком", + "price" : 40 + } +] \ No newline at end of file diff --git a/src/main/resources/sample.fxml b/src/main/resources/sample.fxml new file mode 100644 index 0000000..1bb4418 --- /dev/null +++ b/src/main/resources/sample.fxml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/target/classes/Methods/Automata$States.class b/target/classes/Methods/Automata$States.class new file mode 100644 index 0000000..7ed2c82 Binary files /dev/null and b/target/classes/Methods/Automata$States.class differ diff --git a/target/classes/Methods/Automata.class b/target/classes/Methods/Automata.class new file mode 100644 index 0000000..cab2444 Binary files /dev/null and b/target/classes/Methods/Automata.class differ diff --git a/target/classes/image/coffe.png b/target/classes/image/coffe.png new file mode 100644 index 0000000..6f88150 Binary files /dev/null and b/target/classes/image/coffe.png differ diff --git a/target/classes/menu.json b/target/classes/menu.json new file mode 100644 index 0000000..eb2fb16 --- /dev/null +++ b/target/classes/menu.json @@ -0,0 +1,34 @@ +[ + { + "name": "Чай черный с лимоном", + "price" : 20 + }, + { + "name": "Чай черный с бергамотом", + "price" : 30 + }, + { + "name": "Чай зеленый", + "price" : 20 + }, + { + "name": "Чай зеленый с лимоном", + "price" : 30 + }, + { + "name": "Капучино", + "price" : 45 + }, + { + "name": "Кофе зерновой молотый", + "price" : 35 + }, + { + "name": "Латте", + "price" : 45 + }, + { + "name": "Кофе зерновой с молоком", + "price" : 40 + } +] \ No newline at end of file diff --git a/target/classes/sample.fxml b/target/classes/sample.fxml new file mode 100644 index 0000000..1bb4418 --- /dev/null +++ b/target/classes/sample.fxml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/target/classes/sample/Controller$1.class b/target/classes/sample/Controller$1.class new file mode 100644 index 0000000..27b3209 Binary files /dev/null and b/target/classes/sample/Controller$1.class differ diff --git a/target/classes/sample/Controller$2$1.class b/target/classes/sample/Controller$2$1.class new file mode 100644 index 0000000..150a246 Binary files /dev/null and b/target/classes/sample/Controller$2$1.class differ diff --git a/target/classes/sample/Controller$2.class b/target/classes/sample/Controller$2.class new file mode 100644 index 0000000..8b2a06e Binary files /dev/null and b/target/classes/sample/Controller$2.class differ diff --git a/target/classes/sample/Controller$3$1.class b/target/classes/sample/Controller$3$1.class new file mode 100644 index 0000000..8c2d08e Binary files /dev/null and b/target/classes/sample/Controller$3$1.class differ diff --git a/target/classes/sample/Controller$3.class b/target/classes/sample/Controller$3.class new file mode 100644 index 0000000..55fae82 Binary files /dev/null and b/target/classes/sample/Controller$3.class differ diff --git a/target/classes/sample/Controller$4$1.class b/target/classes/sample/Controller$4$1.class new file mode 100644 index 0000000..730c737 Binary files /dev/null and b/target/classes/sample/Controller$4$1.class differ diff --git a/target/classes/sample/Controller$4.class b/target/classes/sample/Controller$4.class new file mode 100644 index 0000000..76533dd Binary files /dev/null and b/target/classes/sample/Controller$4.class differ diff --git a/target/classes/sample/Controller.class b/target/classes/sample/Controller.class new file mode 100644 index 0000000..2fa8927 Binary files /dev/null and b/target/classes/sample/Controller.class differ diff --git a/target/classes/sample/Main.class b/target/classes/sample/Main.class new file mode 100644 index 0000000..629ceb8 Binary files /dev/null and b/target/classes/sample/Main.class differ