Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
71 lines (48 loc) · 2.82 KB
/
Copy pathMain.java
File metadata and controls
71 lines (48 loc) · 2.82 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
import java.util.HashMap;
public class Main {
public static int friendsCount;
static UserInputs userInputs = new UserInputs();
static UserInputs.StringInput stringInput = userInputs.new StringInput();
static UserInputs.FloatInput floatInput = userInputs.new FloatInput();
static UserInputs.IntInput intInput = userInputs.new IntInput();
public static Product product = new Product();
public static Formatter formatter = new Formatter();
public static void setFriends() {
while (friendsCount <= 1) {
System.out.print("Введите число участников вечеринки: ");
friendsCount = intInput.in();
if (friendsCount > 1) break;
System.out.println("Друзей должно быть больше чем " + friendsCount);
}
}
public static void main(String[] args) {
setFriends();
String outTrigger = "завершить";
System.out.println("Введите название товаров и их стоимость.");
product.productsList = new HashMap<>();
String wordCurrencyCost;
while (true) {
System.out.print("Введите название товара: ");
String productName = stringInput.in();
System.out.print("Введите стоимость товара: ");
float productCost = floatInput.in();
product.productsList.put(productName, productCost);
System.out.println("Товар успешно добавлен.");
float productsAmount = 0;
for (HashMap.Entry<String, Float> product : product.productsList.entrySet()) {
productsAmount += product.getValue();
wordCurrencyCost = formatter.wordCaseCurrency(product.getValue());
System.out.println("Добавленные товары: " + product.getKey() + ", стоимостью " + wordCurrencyCost);
}
product.productsAmount = productsAmount;
wordCurrencyCost = formatter.wordCaseCurrency(productsAmount);
System.out.println("Общая сумма товаров: " + wordCurrencyCost + "\n");
System.out.println("Добавить еще товар? Введите любой символ для продолжения, или `Завершить` для вывода итога и выхода.");
String enteredText = stringInput.in().toLowerCase();
if (enteredText.equals(outTrigger)) break;
}
String amountPerFriend = formatter.wordCaseCurrency((float)product.productsAmount / (float)friendsCount);
System.out.println("\nКаждый друг должен заплатить по " + amountPerFriend);
System.out.println("\nЗавершено");
}
}