diff --git a/AnalogClock/AnalogClock.jar b/AnalogClock/AnalogClock.jar new file mode 100644 index 0000000..eeb9610 Binary files /dev/null and b/AnalogClock/AnalogClock.jar differ diff --git a/AnalogClock/resources/1.mp3 b/AnalogClock/resources/1.mp3 new file mode 100644 index 0000000..e3b80df Binary files /dev/null and b/AnalogClock/resources/1.mp3 differ diff --git a/AnalogClock/resources/2.png b/AnalogClock/resources/2.png new file mode 100644 index 0000000..d760de9 Binary files /dev/null and b/AnalogClock/resources/2.png differ diff --git a/AnalogClock/src/AnalogClock.java b/AnalogClock/src/AnalogClock.java new file mode 100644 index 0000000..8b2be45 --- /dev/null +++ b/AnalogClock/src/AnalogClock.java @@ -0,0 +1,120 @@ +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 AnalogClock extends Application{ + @Override + public void start(Stage stage) throws Exception { + + Image image = new Image("/2.png", 580, 580, false, false); + ImageView imageView = new ImageView(image); + Calendar calendar = GregorianCalendar.getInstance(); + + URL resource = AnalogClock.class.getResource("/1.mp3"); + Media media = new Media(resource.toString()); + MediaPlayer mediaPlayer = new MediaPlayer(media); + mediaPlayer.play(); + + Circle face = new Circle(300,300,7); + face.setFill(Color.BLACK); + + Line secondHand = new Line(0,35,0,-200); + secondHand.setTranslateX(300); + secondHand.setTranslateY(300); + secondHand.setStroke(Color.YELLOW); + secondHand.setStrokeWidth(10); + secondHand.setStrokeLineCap(StrokeLineCap.ROUND); + + Line minuteHand = new Line(0,0,0,-170); + minuteHand.setTranslateX(300); + minuteHand.setTranslateY(300); + minuteHand.setStroke(Color.YELLOW); + minuteHand.setStrokeWidth(10); + minuteHand.setStrokeLineCap(StrokeLineCap.ROUND); + + Line hourHand = new Line(0,0,0,-140); + hourHand.setTranslateX(300); + hourHand.setTranslateY(300); + hourHand.setStroke(Color.YELLOW); + hourHand.setStrokeWidth(10); + 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/CoffeeAutomat/CoffeeAutomat.jar b/CoffeeAutomat/CoffeeAutomat.jar new file mode 100644 index 0000000..7d2a5c3 Binary files /dev/null and b/CoffeeAutomat/CoffeeAutomat.jar differ diff --git a/CoffeeAutomat/pom.xml b/CoffeeAutomat/pom.xml new file mode 100644 index 0000000..731fc3a --- /dev/null +++ b/CoffeeAutomat/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + niit + CoffeeAutomat + 1.0-SNAPSHOT + + + + + src/main/resources + + + + + + \ No newline at end of file diff --git a/CoffeeAutomat/src/main/java/sample/Automat.java b/CoffeeAutomat/src/main/java/sample/Automat.java new file mode 100644 index 0000000..5b4d344 --- /dev/null +++ b/CoffeeAutomat/src/main/java/sample/Automat.java @@ -0,0 +1,166 @@ +package sample; + +import sun.misc.IOUtils; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Paths; + +public class Automat { + enum STAGES { + OFF, WAIT,ACCEPT, CHECK, COOK} + private int cash; + private ArrayList menu = new ArrayList(); + int[] prices; + private STAGES stage; + + Automat(){ + //download menu + /* try{ //in the first time I wrote like that + // URL resource= Automat.class.getResource("/menu.txt"); + // File file = Paths.get(resource.toURI()).toFile(); + // FileReader fr = new FileReader(file); + + //for jar need to read like this, but we into constructor(static method, + // toString() - not static!!! + InputStream inputStream=getClass().getResourceAsStream("/menu.txt"); + String fr= (String) IOUtils.toString(inputStream, StandardCharsets.UTF_8); + BufferedReader reader = new BufferedReader(fr); + String line=null; + + while ((line=reader.readLine()) != null) { + menu.add(line); + } + } + catch (URISyntaxException e) { + e.printStackTrace(); } + catch (FileNotFoundException e){ + e.printStackTrace(); } + catch (java.io.IOException e){ + e.printStackTrace(); } + */ + //I am forced to initialize like this + menu.add(" Expresso"); + menu.add(" Americano"); + menu.add("Cappuccino"); + menu.add(" Mokachino"); + menu.add(" Dalgona"); + prices = new int[]{30,35,45,40,45}; //array initialization + stage = STAGES.OFF; //ready for work! + } + + public int getCash(){ + return cash; + } + + public STAGES on(){ + if (stage == STAGES.OFF) + stage = STAGES.WAIT; + + return stage; + } + + public STAGES getStage(){ + return stage; + } + + public ArrayList getMenu(){ + ArrayList theMenu = new ArrayList(); + if (stage == STAGES.WAIT || stage == STAGES.ACCEPT) + for (int i = 0; i < menu.size(); i++) { + theMenu.add(menu.get(i) + " " + prices[i] + " rub."); + } + + return theMenu; + } + + public int coin(int coins){ + if (stage == STAGES.WAIT || stage == STAGES.ACCEPT) { + stage = STAGES.ACCEPT; + cash=cash+coins; + } + + return cash; + } + + public boolean choice(int numberCoffee){ + + if (stage == STAGES.ACCEPT) { + stage = STAGES.CHECK; + //System.out.println("Choose coffee from the menu."); //can to be, but we have args of this method + + if(check(prices[numberCoffee])) { //check money + cook(numberCoffee); + return true;} + + else //if cash=0){ + cash=cash-priceCoffee; //for surrender + return true; + } + } + + return false; + } + + protected STAGES cook(int numberCoffee){ + if (stage == STAGES.CHECK) { + stage = STAGES.COOK; + //System.out.println("Making " + menu.get(numberCoffee) + " begins."); + //System.out.println("Expect..."); + try { + Thread.sleep(1500); + } catch (InterruptedException e){ + e.printStackTrace(); + } + //System.out.println("Coffee tree for your coffee has already been planted."); + //System.out.println("It remains to wait for the first grains..."); + try { + Thread.sleep(2000); + } catch (InterruptedException e){ + e.printStackTrace(); + } + //System.out.println("This is a joke)))"); + finish(numberCoffee); + } + + return stage; + } + + protected int finish(int numberCoffee){ + if (stage == STAGES.COOK) { + stage = STAGES.WAIT; + if(cash>0) //for surrender + cash=0;//System.out.println("Take your remaining money: "+cash+" rub."); + } + + return cash; + } + + + public int cancel(boolean leaving){ + if (stage == STAGES.ACCEPT || stage == STAGES.CHECK || stage == STAGES.WAIT) { + stage = STAGES.WAIT; + if((cash>0)&& !leaving) //for surrender in this method too, because user can not want coffee + cash=0;//System.out.println("Take your remaining money: "+cash+" rub."); + } + + return cash; + } + + public STAGES off(){ + if (stage == STAGES.WAIT) + stage = STAGES.OFF; + + return stage; + } +} \ No newline at end of file diff --git a/CoffeeAutomat/src/main/java/sample/Controller.java b/CoffeeAutomat/src/main/java/sample/Controller.java new file mode 100644 index 0000000..85d1a78 --- /dev/null +++ b/CoffeeAutomat/src/main/java/sample/Controller.java @@ -0,0 +1,169 @@ +package sample; + +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.*; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.media.Media; +import javafx.scene.media.MediaPlayer; +import java.net.URL; +import java.util.ArrayList; +import java.util.ResourceBundle; + +public class Controller implements Initializable{ + + @FXML + private Button btnOn; + @FXML + private Button btnOff; + + @FXML + private Button btnAccept; + @FXML + private Button btnGetStage; + @FXML + private Button btnCancel; + @FXML + private Button btnGetCash; + @FXML + private Button btnChoice; + + @FXML + private ImageView ivYourCoffee; + + @FXML + private TextField tfFirst; + @FXML + private TextField tfAccept; + @FXML + private TextField tfSurrender; + + @FXML + private ComboBox cbGetMenu; + + private Automat automate; + private ArrayList forMenu; + Image image; + String[] coffee = new String[]{"Expresso.jpg", "Americano.png","Cappuccino.jpg","Mokachino.jpg","Dalgona.jpg"}; + Media media; + MediaPlayer mediaPlayer; + + @Override + public void initialize(URL location, ResourceBundle resources) { + automate = new Automat(); + image=null; + ivYourCoffee.setImage(null); + tfFirst.setText("Click 'on' to start!"); + } + + @FXML + private void onAction(){ + if(automate.on()== Automat.STAGES.WAIT){ + tfFirst.setText("Ready for work!"); + if(cbGetMenu.getItems().size()==0) { + forMenu = automate.getMenu(); + for (String st : forMenu) + cbGetMenu.getItems().add(st); + } + } + } + + @FXML + private void getStageAction(){ + tfSurrender.setText(""); + ivYourCoffee.setImage(null); + tfFirst.setText("This stage is "+automate.getStage()+"."); + } + + @FXML + private void acceptAction() { + tfSurrender.setText(""); + ivYourCoffee.setImage(null); + if(automate.getStage()==Automat.STAGES.WAIT || automate.getStage()==Automat.STAGES.ACCEPT) { + if (tfAccept.getText().equals("") || !(tfAccept.getText().matches("[-+]?\\d+"))) { + tfFirst.setText("Deposit coins! Your cash = " + automate.getCash() + " rub"); + tfAccept.setText(""); + } else { + automate.coin(Integer.parseInt(tfAccept.getText())); + tfFirst.setText("Your cash = " + automate.getCash() + " rub"); + tfAccept.setText(""); + URL coins = Controller.class.getResource("/coins.mp3"); + media = new Media(coins.toString()); + mediaPlayer = new MediaPlayer(media); + mediaPlayer.play(); + } + } + } + + @FXML + private void getCashAction(){ + tfSurrender.setText(""); + ivYourCoffee.setImage(null); + tfFirst.setText("Your cash = " + automate.getCash() + " rub"); + } + + @FXML + private void choiceAction() { + + tfSurrender.setText(""); + ivYourCoffee.setImage(null); + if(automate.getStage()==Automat.STAGES.ACCEPT || automate.getStage()==Automat.STAGES.WAIT) { + int cashBefore = automate.getCash(); + int i=0; + String choice = cbGetMenu.getValue(); + for(String st : forMenu){ + if(st.equals(choice)) + break; + i++; + } + + if(automate.choice(i)==true){ + + URL toPourCoffee = Controller.class.getResource("/to pour coffee.mp3"); + media = new Media(toPourCoffee.toString()); + mediaPlayer = new MediaPlayer(media); + mediaPlayer.play(); + + image=new Image(coffee[i]); + ivYourCoffee.setImage(image); + ivYourCoffee.setFitHeight(150); + ivYourCoffee.setFitWidth(175); + + if((cashBefore-automate.prices[i])>0) { + tfFirst.setText("Done! Take your coffee and a surrender!"); + tfSurrender.setText(((Integer) (cashBefore - automate.prices[i])).toString()); + } + else + tfFirst.setText("Done!!!"); + } + else //if automate.choice(i)==false + tfFirst.setText("Your cash < price of the coffee!"); + } + else + tfFirst.setText("Invalid command for Choice!"); + } + + @FXML + private void cancelAction(){ + ivYourCoffee.setImage(null); + if(automate.getCash()!=0) + tfFirst.setText("Take the money!"); + else + tfFirst.setText(""); + tfSurrender.setText(((Integer)automate.getCash()).toString()); + automate.cancel(false); + } + + @FXML + private void offAction(){ + if(automate.off()== Automat.STAGES.OFF){ + tfFirst.setText("Click 'on' to start!"); + cbGetMenu.getItems().clear(); + tfSurrender.setText(""); + ivYourCoffee.setImage(null); + } + else + tfFirst.setText("Invalid command for Off!"); + } +} \ No newline at end of file diff --git a/CoffeeAutomat/src/main/java/sample/Main.java b/CoffeeAutomat/src/main/java/sample/Main.java new file mode 100644 index 0000000..90e50ce --- /dev/null +++ b/CoffeeAutomat/src/main/java/sample/Main.java @@ -0,0 +1,26 @@ +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")); + Scene scene=new Scene(root); + scene.getStylesheets().add(getClass().getResource("/myCSS.css").toExternalForm()); + primaryStage.setTitle("Coffee Automat"); + primaryStage.setScene(scene); + primaryStage.show(); + } + + + public static void main(String[] args) { + launch(args); + } +} diff --git a/CoffeeAutomat/src/main/resources/2.jpg b/CoffeeAutomat/src/main/resources/2.jpg new file mode 100644 index 0000000..2ae0b1b Binary files /dev/null and b/CoffeeAutomat/src/main/resources/2.jpg differ diff --git a/CoffeeAutomat/src/main/resources/Americano.png b/CoffeeAutomat/src/main/resources/Americano.png new file mode 100644 index 0000000..65a32e3 Binary files /dev/null and b/CoffeeAutomat/src/main/resources/Americano.png differ diff --git a/CoffeeAutomat/src/main/resources/Cappuccino.jpg b/CoffeeAutomat/src/main/resources/Cappuccino.jpg new file mode 100644 index 0000000..8f27973 Binary files /dev/null and b/CoffeeAutomat/src/main/resources/Cappuccino.jpg differ diff --git a/CoffeeAutomat/src/main/resources/Dalgona.jpg b/CoffeeAutomat/src/main/resources/Dalgona.jpg new file mode 100644 index 0000000..f5eb36c Binary files /dev/null and b/CoffeeAutomat/src/main/resources/Dalgona.jpg differ diff --git a/CoffeeAutomat/src/main/resources/Expresso.jpg b/CoffeeAutomat/src/main/resources/Expresso.jpg new file mode 100644 index 0000000..bb3b98c Binary files /dev/null and b/CoffeeAutomat/src/main/resources/Expresso.jpg differ diff --git a/CoffeeAutomat/src/main/resources/Mokachino.jpg b/CoffeeAutomat/src/main/resources/Mokachino.jpg new file mode 100644 index 0000000..4cdd2e5 Binary files /dev/null and b/CoffeeAutomat/src/main/resources/Mokachino.jpg differ diff --git a/CoffeeAutomat/src/main/resources/coins.mp3 b/CoffeeAutomat/src/main/resources/coins.mp3 new file mode 100644 index 0000000..c8de781 Binary files /dev/null and b/CoffeeAutomat/src/main/resources/coins.mp3 differ diff --git a/CoffeeAutomat/src/main/resources/menu.txt b/CoffeeAutomat/src/main/resources/menu.txt new file mode 100644 index 0000000..3b4a333 --- /dev/null +++ b/CoffeeAutomat/src/main/resources/menu.txt @@ -0,0 +1,5 @@ + Expresso + Americano +Cappuccino + Mokachino + Dalgona \ No newline at end of file diff --git a/CoffeeAutomat/src/main/resources/myCSS.css b/CoffeeAutomat/src/main/resources/myCSS.css new file mode 100644 index 0000000..5493fd1 --- /dev/null +++ b/CoffeeAutomat/src/main/resources/myCSS.css @@ -0,0 +1,30 @@ +.root{ + //-fx-font-size: 10; + //-fx-background-color: bisque; + -fx-font: bold italic 10pt "LucidaBrightDemiBold"; + -fx-background-image: url("2.jpg"); +} + +.label{ + -fx-font: bold italic 10pt "LucidaBrightDemiBold"; + -fx-border-color: rgba(255, 255, 255, 1.80); + -fx-border-radius: 8; + -fx-padding: 6 6 6 6; + -fx-text-fill: blue; + -fx-background-color: derive(#2e2e2e, 150%); +} + +.text-field{ + -fx-font: bold italic 10pt "LucidaBrightDemiBold"; + -fx-padding: 6 6 6 6; + -fx-text-fill: blue; + -fx-background-color: derive(#2e2e2e, 150%); +} + +.button{ + + -fx-border-color: rgba(255, 255, 255, 1.80); + -fx-border-radius: 8; + -fx-background-color: derive(#2e2e2e, 150%); + -fx-text-fill: blue; +} \ No newline at end of file diff --git a/CoffeeAutomat/src/main/resources/sample.fxml b/CoffeeAutomat/src/main/resources/sample.fxml new file mode 100644 index 0000000..631c62c --- /dev/null +++ b/CoffeeAutomat/src/main/resources/sample.fxml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +