forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCar.java
More file actions
45 lines (40 loc) · 1.27 KB
/
Car.java
File metadata and controls
45 lines (40 loc) · 1.27 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
import java.util.Scanner;
public class Car {
private final Scanner scanner = new Scanner(System.in);
String name;
int speed;
public Car() {
}
public Car(String name, int speed) {
this.name = name;
this.speed = speed;
}
public String checkNameCar() {
String name;
while (true) {
if (scanner.hasNextLine()) {
name = scanner.nextLine();
if (!name.trim().isEmpty()) {
return name;
}
} else {
System.out.println("название автомобиля не может быть пустым");
scanner.nextLine();
}
}
}
public int checkMaxCarSpeed() {
int speed;
while (true) {
if (scanner.hasNextInt()) {
speed = scanner.nextInt();
if (speed > 0 && speed <= 250) {
return speed;
}
} else {
System.out.println("Нечисловое значение скорости, дробное значение скорости, скорость вне допустимого диапазона от 0 до 250");
scanner.next();
}
}
}
}