forked from Annet-Lovett/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
73 lines (61 loc) · 3.72 KB
/
Main.java
File metadata and controls
73 lines (61 loc) · 3.72 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.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
ArrayList <Product> productList = new ArrayList<>();
int amount;
System.out.println("На скольких человек необходимо разделить счёт?");
while (true) {
Scanner sc = new Scanner(System.in);
if (sc.hasNextInt()) {
while (true) {
amount = sc.nextInt();
if (amount < 1) {
System.out.println("Это некорректное значение для подсчёта.");
} else if (amount == 1) {
System.out.println("Деление счёта бессмыслено :)");
} else {
System.out.println("Введите наименование товара и стоимость товара в формате рубли.копейки, например 'Цезарь 250.70'. Для окончания подсчета введите 'Завершить'");
Calculator newCalculator = new Calculator();
sc.nextLine();
while (true) {
Product newProduct = new Product();
String userAnswer = sc.nextLine();
if (!userAnswer.equalsIgnoreCase("завершить")) {
try {
String[] userAnswerArr = userAnswer.split(" ");
String price = userAnswerArr[userAnswerArr.length - 1];
String name = userAnswer.replaceAll(price, "");
newProduct.setProductName(name);
newProduct.setProductPrice(price);
newCalculator.setAllProductPrice(newProduct.getProductPrice());
productList.add(newProduct);
System.out.println("Товар успешно добавлен в список");
System.out.println("Хотите добавить еще товар или завершить подсчёт? Для окончания подсчета введите 'Завершить'");
} catch (NumberFormatException e) {
System.out.println("Неверный формат цены. Повторите попытку");
} catch (Exception e) {
System.out.println("Неверный формат товара");
}
}
else {
break;
}
}
if (newCalculator.getAllProductPrice() != 0.00) {
System.out.println("Добавленные товары:");
for (Product eachProduct: productList) {
System.out.println(eachProduct.getProductInfo());
}
System.out.println("Сумма к оплате каждого гостя: " + newCalculator.getGuestBill(amount));
break;
}
}
}
break;
} else {
System.out.println("Неправильный ввод. Введите корректное цифровое значение");
}
}
}
}