Repository navigation
Expand file tree
/
Copy pathAuto.java
More file actions
52 lines (45 loc) · 1.54 KB
/
Copy pathAuto.java
File metadata and controls
52 lines (45 loc) · 1.54 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
import java.util.Scanner;
public class Auto {
String name;
double speed;
private double MAX_SPEED = 250.;
public Auto(String name, double speed) {
this.name = name;
this.speed = speed;
}
public Auto(){
this.name = "name";
this.speed = 0;
}
public void input(){
nameInput();
speedInput();
}
private void nameInput(){
System.out.println("Введите название автомобиля:");
Scanner scanner = new Scanner(System.in);
this.name = scanner.nextLine();
}
private void speedInput(){
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Введите скорость автомобиля " + this.name + " в км/ч:" );
if (!scanner.hasNextDouble()) {
System.out.println("Вы ввели не число!!! повторите ввод!!!\n\n");
String temp= scanner.next();
}
else {
this.speed = scanner.nextDouble();
if ((this.speed > 0.) && (this.speed < MAX_SPEED)) {
break;
}
else {
System.out.println("Некорректное значение скорости, повторите ввод!!!\n\n");
}
}
}
}
public void print(){
System.out.println("Автомобиль " +this.name+ " со скоростью " + this.speed+ " км/ч;");
}
}