forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputRacerData.java
More file actions
40 lines (32 loc) · 1.17 KB
/
InputRacerData.java
File metadata and controls
40 lines (32 loc) · 1.17 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
import java.util.Scanner;
public class InputRacerData {
public static Auto inputRacerData(Scanner scanner) {
String inputName;
while (true) {
System.out.println("Введите имя гонщика: ");
inputName = scanner.nextLine();
if (!inputName.isEmpty()) {
break;
} else {
System.out.println("Введите непустое имя");
}
}
int inputSpeed;
while (true) {
System.out.println("Введите скорость гонщика: ");
if (scanner.hasNextInt()) {
inputSpeed = scanner.nextInt();
scanner.nextLine();
if (inputSpeed > 0 && inputSpeed < 250) {
break;
} else {
System.out.println("Введите значение в пределах от 0 до 250");
}
} else {
System.out.println("Введите корректное значение");
scanner.nextLine();
}
}
return new Auto(inputName, inputSpeed);
}
}