Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
119 lines (108 loc) · 3.7 KB
/
Copy pathMain.java
File metadata and controls
119 lines (108 loc) · 3.7 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
RushLeMann rushLeMann = new RushLeMann("", 0);
Scanner scanner = new Scanner(System.in);
String staff = "Введите заново: ";
System.out.println("Введите названия первого автомобиля: ");
String name1 = scanner.next();
while ((name1 == null) || (name1.isEmpty())) {
System.out.println(staff);
name1 = scanner.next();
}
System.out.println("Введите скорость первого автомобиля: ");
int speed1;
while (true) {
if (scanner.hasNextInt()) {
speed1 = scanner.nextInt();
if (speed1 <= 0 || speed1 > 250) {
System.out.println(staff);
} else {
break;
}
} else {
System.out.println(staff);
scanner.next();
}
}
Auto auto1 = new Auto(name1, speed1);
rushLeMann.rushLeader(auto1);
System.out.println("Введите названия второго автомобиля: ");
String name2 = scanner.next();
while ((name2 == null) || (name2.isEmpty())) {
System.out.println(staff);
name2 = scanner.next();
}
System.out.println("Введите скорость второго автомобиля: ");
int speed2;
while (true) {
if (scanner.hasNextInt()) {
speed2 = scanner.nextInt();
if (speed2 <= 0 || speed2 > 250) {
System.out.println(staff);
} else {
break;
}
} else {
System.out.println(staff);
scanner.next();
}
}
Auto auto2 = new Auto(name2, speed2);
rushLeMann.rushLeader(auto2);
System.out.println("Введите названия третьего автомобиля: ");
String name3 = scanner.next();
while ((name3 == null) || (name3.isEmpty())) {
System.out.println(staff);
name3 = scanner.next();
}
System.out.println("Введите скорость третьего автомобиля: ");
int speed3;
while (true) {
if (scanner.hasNextInt()) {
speed3 = scanner.nextInt();
if (speed3 <= 0 || speed3 > 250) {
System.out.println(staff);
} else {
break;
}
} else {
System.out.println(staff);
scanner.next();
}
}
Auto auto3 = new Auto(name3, speed3);
rushLeMann.rushLeader(auto3);
System.out.println("Победитель: " + rushLeMann.leader);
}
}
class RushLeMann {
int currentDistance;
String leader;
int distance;
RushLeMann(String leader, int currentDistance){
this.leader = leader;
this.currentDistance = currentDistance;
}
public int calculationCurrentDistance(Auto auto){
return distance = 24 * auto.speedAuto;
}
public String rushLeader(Auto auto) {
if (currentDistance < calculationCurrentDistance(auto)){
currentDistance = calculationCurrentDistance(auto);
leader = auto.nameAuto;
}
else {
return leader;
}
return leader;
}
}
class Auto {
String nameAuto;
int speedAuto;
Auto(String nameAuto, int speedAuto) {
this.nameAuto = nameAuto;
this.speedAuto = speedAuto;
}
}