Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
66 lines (60 loc) · 2.67 KB
/
Copy pathMain.java
File metadata and controls
66 lines (60 loc) · 2.67 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Calculator calculator = new Calculator();
int numOfVisitors;
String exit = "Завершить";
while (true) {
System.out.println("На скольких человек необходимо разделить счёт?");
if (scanner.hasNextInt()) {
numOfVisitors = scanner.nextInt();
if (numOfVisitors < 1) {
System.out.println("Это некорректное значение для подсчёта.");
} else if (numOfVisitors == 1) {
System.out.println("Нет смысла делить счёт на одного человека.");
} else {
break;
}
} else {
System.out.println("Введите число.");
scanner.next();
}
}
while (true) {
System.out.println("Введите название товара");
Order order = new Order();
order.setNameOrder(scanner.next());
System.out.println("Введите стоимость товара");
do {
if (scanner.hasNextDouble()) {
double price = scanner.nextDouble();
if (price > 0) {
order.setPrice(price);
calculator.add(order);
System.out.println("Товар успешно добавлен");
System.out.printf(
"Общая сумма всех товаров: %.2f %s %n",
calculator.sumOrder(),
calculator.rubEnd(calculator.sumOrder())
);
break;
} else {
System.out.println("Ошибка. Введите положительное число.");
}
} else {
System.out.println("Ошибка. Введите сумму.");
scanner.next();
}
} while (true);
System.out.println("Хотите добавить ещё товар?");
String stop = scanner.next().trim();
if (stop.equalsIgnoreCase(exit)) {
System.out.println("Добавленные товары: ");
calculator.nameOrder(numOfVisitors);
scanner.close();
break;
}
}
}
}