forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRace.java
More file actions
36 lines (29 loc) · 986 Bytes
/
Race.java
File metadata and controls
36 lines (29 loc) · 986 Bytes
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
public class Race {
public static String race(Car[] carArray) {
int[] distance = new int[3];
String leader = "";
for(int i = 0 ; i < 3; i++) {
distance[i] = 24 * carArray[i].speedCar;
}
int max = -1;
for (int i=0; i < carArray.length; i++) {
if (carArray[i].speedCar > max) {
max = carArray[i].speedCar;
leader = carArray[i].nameCar;
}
}
int count = 0;
for (int i=0; i < carArray.length; i++) {
if (carArray[i].speedCar == max) {
count = count + 1;
}
}
if (count > 1) {
System.out.println("В этой гонке победителя нет, попробуйте запустить программу снова!");
}
else {
System.out.println("Самая быстрая машина: " + leader);
}
return leader;
}
}