Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
66 lines (55 loc) · 2.71 KB
/
Copy pathMain.java
File metadata and controls
66 lines (55 loc) · 2.71 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.InputMismatchException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String goodName;
int peopleCount;
System.out.println("Привет!\nНа скольких человек будем делить счёт?" +
" \n\uD83D\uDC49 введи значение: ");
while (true) {
try {
peopleCount = sc.nextInt();
if (peopleCount > 1) break;
} catch (InputMismatchException e) {
System.out.println("Неверный формат ввода! Введите положительное число больше 1 ");
sc.nextLine();
}
System.out.println("\uD83D\uDE20 Введите положительное число больше 1 ");
}
Calculator calculator = new Calculator(peopleCount);
while (true) {
System.out.println("Введите название товара: ");
goodName = sc.next();
if (goodName.equalsIgnoreCase("завершить")) {
break;
}
while (true) {
try {
System.out.println("Введите стоимость товара в формате XX.YY : ");
double newPrice = Double.parseDouble(sc.next());
if (newPrice <= 0) {
System.out.println("Цена должна быть положительным числом!");
} else {
calculator.addPrice(newPrice);
System.out.printf("Товар %s успешно добавлен\n", goodName);
System.out.println("Общая сумма на данный момент: "
+ calculator.getMoneySum());
break;
}
} catch (NumberFormatException e) {
System.out.println("Цена должна быть положительным числом!");
sc.nextLine();
}
}
calculator.storage.add(goodName);
System.out.println("Вы хотите добавить ещё один товар? Если нет, введите - завершить");
}
System.out.println("Добавленные товары: ");
for (String good : calculator.storage) {
System.out.println(" ** " + good + " ** ");
}
DataOutput finalOutput = new DataOutput();
finalOutput.showMessage(calculator.getPersonalPrice());
}
}