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
39 lines (35 loc) · 1.57 KB
/
Race.java
File metadata and controls
39 lines (35 loc) · 1.57 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
import java.util.ArrayList;
import java.util.Collections;
public class Race {
static String winner;
static int start = 0;
static int winnerDistance = 0;
public static int distance24h(int speed) {
return speed * 24;
}
public static void isWinner(String name, int distance) {
if (distance > start) {
start = distance;
winner = name;
winnerDistance = distance24h(distance);
}
}
public static void check (ArrayList<Auto> checkList) {
int count = 0;
Collections.sort(checkList);
for (int i = 0; i < checkList.size()-1; i++) {
if (checkList.get(i).speed == checkList.get(i+1).speed){
count++;
}
}
if (count == (checkList.size()-1)){
System.out.println("Все финишировали одновременно!");
} else if (count == 1) {
System.out.println("Две машины: \'"+checkList.get(0).name+"\' и \'"+ checkList.get(1).name+"\' пришли одновременно, проехав "+distance24h(checkList.get(0).speed)+ " километров за 24 часа.");
} else if (count == 0) {
System.out.println("Победитель финишировал на машине: \'"+checkList.get(0).name+"\', проехав "+distance24h(checkList.get(0).speed) + " километров за 24 часа.");
} else {
System.out.println("Несколько участников пришли к финишу одновременно!");
}
}
}