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
34 lines (29 loc) · 1.31 KB
/
Calculator.java
File metadata and controls
34 lines (29 loc) · 1.31 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
import java.util.ArrayList;
public class Calculator {
private final ArrayList<Good> goodList = new ArrayList<>();
public boolean addGood(Good good) {
return goodList.add(good);
}
public ArrayList<Good> getGoodList() {
return goodList;
}
public void printResult(int count) {
double totalSum = 0.0;
double separationSum;
double currentPrice;
String goodTemplate = "Товар: %s\t\tЦена: %.2f %s";
String totalSumTemplate = "Полная сумма: %.2f %s";
String separationTemplate = "Каждому человеку компании (из %d челевок) нужно заплатить %.2f %s";
System.out.println("Добавленные товары:\n");
Good good;
for (Good value : goodList) {
good = value;
currentPrice = good.getPrice();
System.out.println(String.format(goodTemplate, good.getName(), currentPrice, Formatter.getCurrency(currentPrice)));
totalSum += currentPrice;
}
separationSum = totalSum / count;
System.out.println(String.format(totalSumTemplate, totalSum, Formatter.getCurrency(totalSum)));
System.out.println(String.format(separationTemplate, count, separationSum, Formatter.getCurrency(totalSum)));
}
}