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
53 lines (51 loc) · 1.67 KB
/
Main.java
File metadata and controls
53 lines (51 loc) · 1.67 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
import java.util.Scanner;
class Car {
final String name;
final int speed;
final static int MIN_SPEED = 0;
final static int MAX_SPEED = 250;
Car(String carName, int carSpeed) {
this.name = carName;
this.speed = carSpeed;
}
}
class Race {
String leader;
int distance = 0;
public void calculate(Car car) {
int dis = 24 * car.speed;
if (distance < dis) {
distance = dis;
leader = car.name;
}
}
}
public class Main {
public static void main(String[] args) {
Race granPriMonaco = new Race();
Scanner scanner = new Scanner(System.in);
int i;
for (i = 1; i <= 3; i++) {
System.out.println("- Введите название машины №" + i + ":");
String name = scanner.next();
int speed;
while (true) {
try {
System.out.println("Введите скорость машины №" + i + ":");
speed = scanner.nextInt();
if ((Car.MIN_SPEED > speed) || (speed > Car.MAX_SPEED)) {
System.out.println("Неправильная скорость");
} else {
break;
}
} catch (Exception e) {
System.out.println("Неправильная скорость");
scanner.nextLine();
}
}
Car result = new Car(name, speed);
granPriMonaco.calculate(result);
}
System.out.println("Самая быстрая машина: " + granPriMonaco.leader);
}
}