Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
80 lines (76 loc) · 3.68 KB
/
Copy pathMain.java
File metadata and controls
80 lines (76 loc) · 3.68 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int person = 0;
while (true) {
System.out.println("На скольких человек будет разделен счет?:");
if (scanner.hasNextInt()) {
person = scanner.nextInt();
} else {
System.out.println("Количество человек должно быть целым числом");
scanner.next();
continue;
}
if (person < 1) {
System.out.println("Количество человек меньше 1. Это некорректное значение для подсчёта.");
} else if (person == 1) {
System.out.println("Количество человек равно 1. В этом случае нет смысла ничего считать и делить.");
} else {
break;
}
}
Calculator calculator = new Calculator();
float price = 0;
String product = "";
String command = "";
while (true) {
System.out.println("Введите стоимость и товар:");
if (scanner.hasNextFloat()) {
price = scanner.nextFloat();
} else {
System.out.println("Стоимость должна быть числом");
scanner.next();
continue;
}
product = scanner.next();
calculator.addItem(price, product);
System.out.println("Товар добавлен в счет");
System.out.println("Общаая сумма:" + calculator.sum + "Товары:" + calculator.items);
System.out.println("Хотите еще добавить тровар? Если нет, то введите команду \"Завершить\"");
command = scanner.next();
if (command.equalsIgnoreCase("Завершить")) {
break;
}
}
System.out.println("Итоговый счет:\n" + calculator.items);
int list = (int) Math.floor(calculator.sum / (double) person);
if (list == 1) {
System.out.println(String.format("Сумма на одного человека:%.2f рубль", calculator.sum / (double) person));
} else if (2 <= list && list <= 4) {
System.out.println(String.format("Сумма на одного человека:%.2f рубля", calculator.sum / (double) person));
} else if (5 <= list && list <= 20) {
System.out.println(String.format("Сумма на одного человека:%.2f рублей", calculator.sum / (double) person));
} else {
int digit = list % 10;
switch (digit) {
case 0:
case 6:
case 9:
case 8:
case 7:
case 5:
System.out.println(String.format("Сумма на одного человека:%.2f рублей", calculator.sum / (double) person));
break;
case 1:
System.out.println(String.format("Сумма на одного человека:%.2f рубль", calculator.sum / (double) person));
break;
case 2:
case 4:
case 3:
System.out.printf("Сумма на одного человека:%.2f рубля%n", calculator.sum / (double) person);
break;
}
}
}
}