forked from Yandex-Practicum/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
106 lines (84 loc) · 3.96 KB
/
Main.java
File metadata and controls
106 lines (84 loc) · 3.96 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import java.util.Scanner;
import mypackage.Product;
import mypackage.ProductBusket;
public class Main {
public static String rubleDeclination(double numberExample) {
int rouble = (int) Math.floor(numberExample);
if (rouble >= 5 && rouble <= 20) {
return "рублей";
}
switch (rouble % 10) {
case 1:
return "рубль";
case 2:
case 3:
case 4:
return "рубля";
default:
return "рублей";
}
}
public static void main(String[] args) {
System.out.println(Main.class.getPackage().getName());
int numberOfGuests = 0;
Scanner scanner = new Scanner(System.in);
while (true) {
try {
System.out.println("Введите количество гостей.");
numberOfGuests = scanner.nextInt();
if (numberOfGuests <= 1)
System.out.println("Ошибка. Введите корректное количество гостей заново.");
else
break;
} catch (Exception e) {
String wrongInput = scanner.next();
System.out.println("Ошибка. Введите корректное количество гостей заново.");
}
}
ProductBusket myBusket = new ProductBusket();
while (true) {
String prodName = "";
if (myBusket.productList.size() == 0) {
System.out.println("Введите название блюда");
prodName = scanner.next();
} else {
System.out.println("Введите название блюда, если хотите добавить товар или 'завершить', если товаров больше нет.");
prodName = scanner.next();
if (prodName.equalsIgnoreCase("Завершить")) {
break;
}
}
// System.out.println("Введите название блюда.");
// String prodName = scanner.next();
// if (prodName.equalsIgnoreCase("Завершить")) {
// break;
// }
if (prodName.matches("[а-яА-Я]+")) {
while (true) {
try {
System.out.println("Введите стоимость блюда в формате рубли.копейки.");
Double prodPrice = scanner.nextDouble();
if (prodPrice > 0) {
Product a = new Product(prodName, prodPrice);
myBusket.addToBusket(a);
System.out.println("Блюдо успешно добавлено в корзину!");
break;
} else {
System.out.println("Ошибка. Неверно введена стоимость блюда. Введите снова!");
}
} catch (Exception e) {
String WrongName = scanner.next();
System.out.println("Ошибка. Неверно введена стоимость блюда. Введите снова!");
continue;
}
}
} else {
System.out.println("Неккоректно введено название блюда введите снова.");
}
}
myBusket.displayProducts();
double result = ProductBusket.finalPrice / numberOfGuests;
double finalResult = Math.round(result * 100.0) / 100.0;
System.out.println("Каждый гость заплатит: " + finalResult + " " + rubleDeclination(finalResult) + ".");
}
}