Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
48 lines (42 loc) · 2.06 KB
/
Copy pathMain.java
File metadata and controls
48 lines (42 loc) · 2.06 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
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double finalSum;
String finalList = "Добавленные товары:%s \nИтого сумма: %.2f %s на каждого гостя.";
Calculator calculator = new Calculator();
EndFormater formater = new EndFormater();
CountPeople counter = new CountPeople();
int countGuests = 1;
countGuests = counter.countPerson(countGuests);
while (true) {
System.out.println("Введите название товара:");
String countNames = scanner.nextLine().trim();
while (countNames.isEmpty()) {
counter.typeErrorMessage();
countNames = scanner.nextLine().trim();
}
double countPrices;
do {
System.out.println("Введите стоимость товара, большe нуля.");
while (!scanner.hasNextDouble()) {
counter.typeErrorMessage();
scanner.next();
}
countPrices = scanner.nextDouble();
} while (countPrices <= 0);
calculator.calculate(countNames, countPrices);
System.out.println("Товар \"" + countNames + "\" успешно добавлен. Хотите добавить ещё один товар? Введите любые символы.\n"
+ "Или введите \"Завершить\", чтобы завершить процесс добавления товаров.");
String isFinish = scanner.next();
scanner.nextLine();
String finish = "Завершить";
if (isFinish.equalsIgnoreCase(finish)) {
finalSum = calculator.price / countGuests;
System.out.printf((finalList) + "%n", calculator.names, finalSum, formater.formatRubleEnding(finalSum));
break;
}
}
scanner.close();
}
}