Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
63 lines (60 loc) · 2.87 KB
/
Copy pathMain.java
File metadata and controls
63 lines (60 loc) · 2.87 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
import java.text.DecimalFormat;
import java.util.Scanner;
// dev branch for Y.Practicum
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double totalPrice = 0;
DecimalFormat two = new DecimalFormat("#.##");
int quantity;
while (true) {
System.out.println("На сколько человек разделить счет?");
while (!scanner.hasNextInt()) {
System.out.println("Введи целое число больше 1");
scanner.next();
}
quantity = scanner.nextInt();
scanner.nextLine();
if (quantity == 1) {
System.out.println("Нет смысла делить счет. Введи новое число");
}
if (quantity < 1) {
System.out.println("Как может прийти меньше 1 человека?! Дурак) Введи снова");
}
if (quantity > 1) {
System.out.println("Принимай заказ. Будем делить чек на " + quantity + "-х");
break;
}
}
StringBuilder totalName = new StringBuilder("Добавленные товары:\n");
while (true) {
System.out.println("Как называется блюдо?");
String name = scanner.nextLine();
double price = 0;
System.out.println("Сколько стоит блюдо (формат ХХ.ХХ)?");
while (price <= 0) {
while (!scanner.hasNextDouble()) {
System.out.println("Введи число!");
scanner.next();
}
price = scanner.nextDouble();
if (price <= 0) {
System.out.println("Введи нормальную стоимость");
}
}
scanner.nextLine();
totalPrice += price;
totalName.append(name + "\n");
System.out.println("Добавлено " + name + ". Его стоимость " + price + ". Хочешь добавить еще блюдо? Если нет - напиши завершить");
String input = scanner.nextLine();
if (input.equalsIgnoreCase("завершить")) {
System.out.println(totalName);
break;
}
}
double result = totalPrice / quantity;
Formatter ruble = new Formatter();
System.out.println("По счету каждый платит: " + two.format(result) + " " + Formatter.calc(result));
}
}
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости