Repository navigation
Expand file tree
/
Copy pathInput.java
More file actions
64 lines (60 loc) · 2.36 KB
/
Copy pathInput.java
File metadata and controls
64 lines (60 loc) · 2.36 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
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.Scanner;
public class Input {
public static int identifyQuantityPerson() {
Scanner console = new Scanner(System.in);
System.out.println("На скольких человек необходимо разделить счёт?");
int quantityPerson;
while (true) {
if (console.hasNextInt()) {
quantityPerson = console.nextInt();
if (quantityPerson < 1) {
System.out.println("Это некорректное значение для подсчёта");
System.out.println("Введите корректное количество гостей");
}
if (quantityPerson == 1) {
System.out.println("Количество человек равно 1 - нет смысла ничего считать и делить");
System.out.println("Введите корректное количество гостей");
}
if (quantityPerson > 1) {
break;
}
} else {
System.out.println("Введите целое число");
console.next();
}
}
return quantityPerson;
}
public static String checkName() {
Scanner console = new Scanner(System.in);
String line;
while (true) {
if (console.hasNextLine()) {
line = console.next();
break;
} else {
System.out.println("Убедитесь, что вводите название текстом");
console.next();
}
}
return line;
}
public static double checkCost() {
Scanner console = new Scanner(System.in);
double line;
while (true) {
if (console.hasNextDouble()) {
line = console.nextDouble();
if (line > 0) {
break;
} else {
System.out.println("Стоимость товара должна быть больше нуля");
}
} else {
System.out.println("Убедитесь, что вводите дробное число");
console.next();
}
}
return line;
}
}