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
27 lines (23 loc) · 867 Bytes
/
Calculator.java
File metadata and controls
27 lines (23 loc) · 867 Bytes
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
import java.util.ArrayList;
public class Calculator {
ArrayList<Product> products = new ArrayList<>();
public void addProduct(Product product){
if (products.add(product))
System.out.println("Товар успешно добавлен");
}
public void printProducts() {
System.out.println("Добавленные товары:");
for (Product it : products){
System.out.println(it.name + ": " + it.price);
}
}
public void calculateForPersons(int persons) {
double sum = 0f;
for (Product it : products){
sum += it.price;
}
double total = sum / persons;
Formatter format = new Formatter(total);
System.out.println("Сумма, которую должен заплатить каждый: " + format.getStringPrice());
}
}