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
73 lines (62 loc) · 2.09 KB
/
Race.java
File metadata and controls
73 lines (62 loc) · 2.09 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
import java.util.Scanner;
public class Race {
int time = 24;
Scanner scanner;
int speed;
String name;
public Race() {
scanner = new Scanner(System.in);
speed = 0;
name = null;
}
public void getWinner(int[] arrayI, String[] arrayS) {
int[] s = new int[3];
int max = 0;
int num = -1;
for(int i =0; i<3; i++)
{
s[i] = time* arrayI[i];
}
for(int i = 0; i<3;i++)
{
if(s[i]>max)
{
max = s[i];
num += 1;
}
}
if(max == s[0] & max == s[1] || max == s[1] & max == s[2] || max == s[0] & max == s[2] || max == s[0] & max == s[1] & max == s[2])
{
System.out.println("Победителей нет!");
}
else {
System.out.println("Самая быстрая машина: " + arrayS[num]);
}
}
public void setCar() {
System.out.println("Назввание: ");
name = scanner.nextLine();
System.out.println("Скорость: ");
while(!scanner.hasNextInt()) {
scanner.next();
System.out.println("Скорость может быть выражена только целым числом, попробуйте ещё раз: ");
}
speed = scanner.nextInt();
if (!(speed > 0 & speed <= 250)) {
while(!(speed > 0 & speed <= 250)) {
System.out.println("Скорость должна быть больше 0 и меньше 250, попробуйте указать её ещё раз:");
while(!scanner.hasNextInt()) {
scanner.next();
System.out.println("Скорость может быть выражена только целым числом, попробуйте ещё раз: ");
}
speed = scanner.nextInt();
}
}
}
public String returnName() {
return this.name;
}
public int returnSpeed() {
return this.speed;
}
}