Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
109 changes: 109 additions & 0 deletions Clock.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Binary file added ProgectClock.jar
Binary file not shown.
21 changes: 21 additions & 0 deletions lab5.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" name="Maven: org.json:json:20180130" level="project" />
<orderEntry type="library" name="Maven: org.decimal4j:decimal4j:1.0.3" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.6" level="project" />
</component>
</module>
44 changes: 44 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>niit</groupId>
<artifactId>lab5</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
<dependency>
<groupId>org.decimal4j</groupId>
<artifactId>decimal4j</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</project>
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/main/.DS_Store
Binary file not shown.
Binary file added src/main/java/.DS_Store
Binary file not shown.
135 changes: 135 additions & 0 deletions src/main/java/Methods/Automata.java
Original file line number Diff line number Diff line change
@@ -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<String,Integer> 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;i<menu1.length();i++){
JSONObject menu2 = menu1.getJSONObject(i);
Menu.put(menu2.getString("name"),menu2.getInt("price"));
}
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

public String on() {
if (state == States.OFF) {
state = States.WAIT;
}
return state.toString();
}
public String off() {
if (state == States.WAIT) {
state = States.OFF;
}
return state.toString();
}

public Integer getPrice (String name){
int i = Menu.get(name);
return Menu.get(name);
}
public String coin(int coin) {
if ((state == States.WAIT || state == States.ACCEPT || state == States.CHECK)&& coin>0) {
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 "Операция невозможна!";
}
}
Loading