forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
33 lines (24 loc) · 1.05 KB
/
Calculator.java
File metadata and controls
33 lines (24 loc) · 1.05 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
public class Calculator {
String list = "";
float totalPrice = 0;
RubleFormatter formatter = new RubleFormatter();
void add(float price) {
totalPrice += price;
}
void writeToTheList(String nameOfProduct, float priceOfProduct) {
list += nameOfProduct.trim().toLowerCase();
list += " ";
list += priceOfProduct;
list += "\n";
}
void showCheck(int numberOfUsers) {
System.out.println("Добавленные товары:");
System.out.println(list);
String messageTemplateTotalPrice = "Итоговая сумма: %.2f %s.";
String messageTemplateResult = "Каждый должен заплатить %.2f %s.";
String formattedUnit = formatter.formatUnit(totalPrice);
System.out.println(String.format(messageTemplateTotalPrice, totalPrice, formattedUnit));
formattedUnit = formatter.formatUnit(totalPrice / numberOfUsers);
System.out.println(String.format(messageTemplateResult, totalPrice / numberOfUsers, formattedUnit));
}
}