forked from Yandex-Practicum/Java-Module-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAskInfo.java
More file actions
73 lines (65 loc) · 2.61 KB
/
AskInfo.java
File metadata and controls
73 lines (65 loc) · 2.61 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
71
72
73
import java.util.Scanner;
public class AskInfo {
int peopleAmount;
double checkCount;
StringBuilder productList;
AskInfo() {
productList = new StringBuilder();
}
void askPeopleAmount() {
Scanner scanner = new Scanner(System.in);
boolean exceptionHappened;
while (true) {
exceptionHappened = false;
System.out.println("Введите количество гостей:");
try {
peopleAmount = scanner.nextInt();
}
catch (java.util.InputMismatchException e) {
System.out.println("Ошибка ввода, попробуйте еще раз.");
scanner.nextLine();
exceptionHappened = true;
}
if (!exceptionHappened && peopleAmount <= 1) {
System.out.println("Ошибка ввода количества гостей. Количество гостей должно быть больше 1.");
} else if (!exceptionHappened){
break;
}
}
}
void addProductsNameAndPrice() {
String productName;
double price = 0;
boolean exceptionHappened;
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Введите название товара:\nЕсли хотите вывести счет введите: Завершить.");
productName = scanner.next();
if (!productName.equalsIgnoreCase("Завершить")) {
productList.append(productName).append("\n");
}
else {
break;
}
while (true) {
exceptionHappened = false;
System.out.println("Введите цену товара:");
try {
price = scanner.nextDouble();
}
catch (java.util.InputMismatchException e) {
System.out.println("Ошибка ввода. Возможно неверный формат ввода. Повторите ввод.");
scanner.nextLine();
exceptionHappened = true;
}
if (price >= 0 && !exceptionHappened){
checkCount += price;
break;
}
else if (!exceptionHappened) {
System.out.println("Ошибка ввода. Цена не может быть меньше нуля. Повторите ввод.");
}
}
}
}
}