forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
44 lines (39 loc) · 1.56 KB
/
Main.java
File metadata and controls
44 lines (39 loc) · 1.56 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Car[] cars = input();
Car fastest = Race.race(cars);
System.out.println("Самая быстрая машина:");
System.out.println(fastest.name);
}
public static Car[] input(){
Scanner scanner = new Scanner(System.in);
Car[] cars = new Car[3];
double speed = 0;
for (int i=0;i<3;i++){
System.out.println("Введите название машины №"+ (i+1) + ":");
String name = scanner.next();
while (name.isEmpty()){
System.out.println("Неккоректный ввод названии");
System.out.println("Введите название машины №"+ (i+1) + ":");
name = scanner.next();
}
while (true) {
System.out.println("Введите скорость машины №"+ (i+1) + ":");
if (scanner.hasNextDouble()){
speed = scanner.nextDouble();
if (speed > 250 || speed <0){
System.out.println("Неккоректный ввод скорости");
} else {
break;
}
} else {
System.out.println("Неккоректный ввод скорости");
scanner.next();
}
}
cars[i] = new Car(name, speed);
}
return cars;
}
}