forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuto.java
More file actions
39 lines (35 loc) · 1.5 KB
/
Auto.java
File metadata and controls
39 lines (35 loc) · 1.5 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.InputMismatchException;
import java.util.Scanner;
public class Auto {
String name = "";
int speed = 0;
public void getName(int i) {
Scanner scanner = new Scanner(System.in);
System.out.println("- Введите название машины №" + i + ":");
this.name = scanner.next();
while (this.name.isEmpty()) {
System.out.println("- Название машины не может быть пустой строкой");
System.out.println("- Введите название машины №" + i + ":");
this.name = scanner.next();
}
}
public void getSpeed (int i) {
boolean validSpeed = false;
Scanner scanner = new Scanner(System.in);
while (!validSpeed) {
try {
System.out.println("- Введите скорость машины №" + i + ":");
this.speed = scanner.nextInt();
while ((this.speed <= 0) || (this.speed > 250)) {
System.out.println("- Неправильная скорость");
System.out.println("- Введите скорость машины №" + i + ":");
this.speed = scanner.nextInt();
}
validSpeed = true;
} catch(InputMismatchException e) {
System.out.println("- Некорректный формат скорости");
scanner.next();
}
}
}
}