Repository navigation
Expand file tree
/
Copy pathRace.java
More file actions
66 lines (54 loc) · 2.02 KB
/
Copy pathRace.java
File metadata and controls
66 lines (54 loc) · 2.02 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
import static java.lang.Character.isDigit;
import java.util.ArrayList;
import java.util.Scanner;
public class Race {
ArrayList<automobile> MembersRace = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
// Ввод имени
public String InputName() {
while (true) {
System.out.println("— Введите название машины №" + (MembersRace.size() + 1));
String input = scanner.nextLine();
if ((!(input == null)) & (!input.isEmpty())) {
return input;
} else {
System.out.println("— Неправильная наименование ");
}
}
}
//Ввод скорости
public int InputSpeed() {
while (true) {
System.out.println("— Введите скорость машины №" + (MembersRace.size() + 1));
String input = (scanner.nextLine());
boolean isDigit=!(input.isEmpty());
for (int i=0;i<input.length();i++){
isDigit=isDigit & isDigit(input.charAt(i));
}
if (!isDigit) {
;
}
else if ((Integer.parseInt(input) <= 250) & (Integer.parseInt(input) > 0)) {
return Integer.parseInt(input);
}
System.out.println("— Неправильная скорость ");
}
}
//Запуск приложения
public void start() {
for (int i = 0; i < 3; i++) {
MembersRace.add(new automobile(InputName(), InputSpeed()));
}
LeaderCalculation (MembersRace);
}
// Вычисление лидера
public void LeaderCalculation(ArrayList<automobile> MembersRace) {
automobile leader = new automobile("", 0);
for (automobile car : MembersRace) {
if (leader.Speed < car.Speed) {
leader = car;
}
}
System.out.println("Самая быстрая машина: " + leader.Name);
}
}