Repository navigation
Expand file tree
/
Copy pathInput.java
More file actions
70 lines (65 loc) · 2.62 KB
/
Copy pathInput.java
File metadata and controls
70 lines (65 loc) · 2.62 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
65
66
67
68
69
70
import java.util.Locale;
import java.util.Scanner;
public class Input {
public int peopleCount() {
System.out.println("На скольких человек необходимо разделить счет");
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Введите число");
if (!scanner.hasNextInt()) {
System.out.println("Введено не число, попрбуйте заново ввести число");
scanner.nextLine();
} else {
int peopleCount = scanner.nextInt();
if (peopleCount > 1) {
return peopleCount;
}
if (peopleCount <= 1) {
System.out.println("Введенное число должно быть больше 1");
}
}
}
}
public String addProductName() {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Введите название товара");
if (!scanner.hasNext()) {
System.out.println("Введена не строка, попробуйте заного ввести название товара");
scanner.nextLine();
} else {
String productName = scanner.nextLine();
if (!productName.isEmpty()) {
return productName;
}
}
}
}
public double addProductCoast() {
Scanner scanner = new Scanner(System.in).useLocale(Locale.ENGLISH);
while (true) {
System.out.println("Введите стоимость товара");
if (!scanner.hasNextDouble()) {
System.out.println("Стоимость товара должна иметь вид рубли.копейки");
scanner.nextLine();
} else {
double coast = scanner.nextDouble();
if (coast > 0) {
return coast;
} else {
System.out.println("Стоимость должна быть больше 0");
scanner.nextLine();
}
}
}
}
public boolean addProduct() {
Scanner scanner = new Scanner(System.in);
System.out.println("Хотите добавить товар?");
if (scanner.hasNext()) {
String command = scanner.next();
return !command.equalsIgnoreCase("Завершить");
}
return true;
}
}