forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
72 lines (62 loc) · 2.05 KB
/
Main.java
File metadata and controls
72 lines (62 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Проектная работа №1 Java-Module-Project-YP");
Scanner scanner = new Scanner(System.in);
Race race = new Race("",-1);
for (int i=1; i<=3; i++){
System.out.println("— Введите название машины №"+i+":");
String carBrand = scanner.next();
boolean speedLimit = true;
int speed = -1;
while (speedLimit){
System.out.println("— Введите скорость машины №"+i+":");
int curSpeed = 0;
if ( scanner.hasNextInt() ){
curSpeed = scanner.nextInt();
if ( curSpeed < 0 || curSpeed > 250 ) {
System.out.println("— Неправильная скорость");
} else {
speedLimit = false;
}
} else {
scanner.next();
System.out.println("— Неправильная скорость");
}
speed = curSpeed;
}
race.whoIsNewLeader(carBrand, speed);
}
race.sayLeaderName();
scanner.close();
}
}
class Car {
String carBrand;
int speed;
Car (String carBrand, int speed){
this.carBrand = carBrand;
this.speed = speed;
}
}
class Race {
String leader = "";
String carBrand;
int speed;
int distance = 0;
public void whoIsNewLeader (String carBrand, int speed){
int raceTime = 24;
int curDistance = raceTime * speed;
if (curDistance > distance){
leader = carBrand;
distance = curDistance;
}
}
public void sayLeaderName(){
System.out.println("Самая быстрая машина: "+leader);
}
Race (String carBrand, int speed){
this.carBrand = carBrand;
this.speed = speed;
}
}