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
22 lines (18 loc) · 762 Bytes
/
Calculator.java
File metadata and controls
22 lines (18 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.ArrayList;
public class Calculator {
private double totalSum;
ArrayList<Product> products = new ArrayList<>();
public void add(Product product) {
products.add(product);
totalSum += product.price;
}
public void printProducts(int usersNumber) {
System.out.println("Добавленные товары:");
for (Product product : products) {
System.out.printf("%s - %.2f руб.\n", product.name, product.price);
}
double pricePerUser = totalSum / usersNumber;
String formattedRubles = Formatter.getFormattedRubles(pricePerUser);
System.out.printf("Каждый должен заплатить по %.2f %s", pricePerUser, formattedRubles);
}
}