Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
102 lines (80 loc) · 3.69 KB
/
Copy pathMain.java
File metadata and controls
102 lines (80 loc) · 3.69 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
scanner.useDelimiter("\\n");
StringBuilder menu = new StringBuilder();
System.out.println("На сколько человек разделить ваш счет?");
int friends = countFriend(scanner);
int processAdd;
double total = 0;
do {
System.out.println("Укажите название блюда:");
String dish = scanner.next();
while(dish.isEmpty()) {
System.out.println("Название блюда не должно быть пустым.");
dish = scanner.next();
}
menu.append(dish).append("\n");
System.out.println("Укажите стоимость блюда:");
total = total + checkPrice(scanner);
System.out.println("Блюдо добавлено в список");
System.out.println("Желаете добавить еще одно блюдо? (Укажите \"Завершить\" для завершения процесса или введите любые символы, для продолжения)");
processAdd = enterCommand(scanner);
} while(processAdd == 0);
//Выводим калькулятор
double calculate = total / (double)friends;
String bill = String.format("%.2f", calculate);
String sum = String.format("%.2f", total);
Ruble rubleSum = new Ruble();
Ruble rubleBill = new Ruble();
String changeRubleSum = rubleSum.recieveRuble(total);
String changeRubleBill = rubleBill.recieveRuble(calculate);
String resultMenu = menu.toString();
System.out.println("Добавленные блюда:");
System.out.println(resultMenu);
System.out.println("Стоимость заказа:");
System.out.println(sum + changeRubleSum);
System.out.println("Количество гостей:");
System.out.println(friends);
System.out.println("Стоимость чека на каждого:");
System.out.println(bill + changeRubleBill);
}
//Обрабатываем вывод количества друзей
public static int countFriend(Scanner scanner) {
while (true) {
if(scanner.hasNextInt()) {
int number = scanner.nextInt();
if(number <= 1) {System.out.println("Укажите число больше 1.");}
else {return number;}
} else {
System.out.println("Необходимо указать целое число.");
scanner.next();
}
}
}
//Обрабатываем вывод суммы
public static double checkPrice (Scanner scanner) {
while (true) {
if(scanner.hasNextDouble()) {
double price = scanner.nextDouble();
if(price <= 0) {System.out.println("Укажите число больше 0.");}
else {return price;}
} else {
System.out.println("Необходимо указать число.");
scanner.next();
}
}
}
//Решаем, завершать ли нам добавление блюд или продолжать
public static int enterCommand(Scanner scanner) {
String dishAdd = scanner.next();
int command;
if(dishAdd.equalsIgnoreCase("Завершить")) {
command = 1;
} else {
command = 0;
}
return command;
}
}