Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
87 lines (78 loc) · 3.74 KB
/
Copy pathMain.java
File metadata and controls
87 lines (78 loc) · 3.74 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
import java.util.HashMap;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
CalculatorMenu calculatorMenu = new CalculatorMenu();
calculatorMenu.countPerson();
calculatorMenu.menu();
calculatorMenu.costOfOrder();
}
}
class CalculatorMenu {
HashMap<String, Double> menu = new HashMap<>();
private final Scanner scanner = new Scanner(System.in);
private int person = 0;
private double sum = 0;
public void menu() {
while (true) {
System.out.println("Введите название товара");
String menuSting = scanner.next();
if (menuSting.equalsIgnoreCase("Завершить")) {
break;
} else {
System.out.println("Введите стоимость товара руб,коп");
if (scanner.hasNextDouble()) {
double priceDouble = scanner.nextDouble();
if (priceDouble > 0) {
menu.put(menuSting, priceDouble);
System.out.println("Товар успешно добавлен");
System.out.println("Хотите еще добавить товар? если нет введите 'Завершить'");
} else
System.out.println("Стоимость не должна быть отрицательной");
} else {
System.out.println("Некорректный ввод данных, форма ввода стоимости '0,00'");
scanner.next();
}
}
}
for (Double i : menu.values()) { // сложение значейний value, общая стоимость
sum += i;
}
System.out.println("Добавленные товары:");
for (String key : menu.keySet()) {
System.out.println(key);
}
}
public void costOfOrder() {
String[] stringRub = {"рубль", "рубля", "рублей"};
double priseFoPerson = sum / person; // расчет стоимости с каждого клиента
if (priseFoPerson % 100 >= 5 && priseFoPerson % 100 < 20.99) {
System.out.printf("Стоимость покупки с человека: %.2f %s", priseFoPerson, stringRub[2]);
} else if (priseFoPerson % 10 >= 1.00 && priseFoPerson % 10 < 2) {
System.out.printf("Стоимость покупки с человека: %.2f %s", priseFoPerson, stringRub[0]);
;
} else if (priseFoPerson % 10 >= 2 && priseFoPerson % 10 < 5) {
System.out.printf("Стоимость покупки с человека: %.2f %s", priseFoPerson, stringRub[1]);
;
} else System.out.printf("Стоимость покупки с человека: %.2f %s", priseFoPerson, stringRub[2]);
;
}
public void countPerson() {
System.out.println("На скольких человек необходимо разделить счёт.");
while (true) {
if (scanner.hasNextInt()) {
int number = scanner.nextInt();
if (number >= 0) {
person = number;
break;
} else {
System.out.println("Введите число > 0");
}
} else {
System.out.println("некорректное значение для подсчёта, введите положительное число ");
scanner.next();
}
}
System.out.println("Колличество человек = " + person);
}
}