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
28 lines (24 loc) · 1.14 KB
/
Calculator.java
File metadata and controls
28 lines (24 loc) · 1.14 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
import java.util.ArrayList;
public class Calculator {
private final ArrayList<Product> products = new ArrayList<>();
public Product addProduct(String name, double price) {
Product product = new Product(name, price);
products.add(product);
System.out.println("Товар \"" + name + "\" успешно добавлен.");
return product;
}
public boolean promptForNextProduct(String response) {
return !response.equalsIgnoreCase("Завершить");
}
public void displayProductsAndTotal(int countPersons) {
double total = 0;
System.out.println("Все добавленные товары:");
for (Product product : products) {
System.out.println(product);
total += product.getPrice();
}
System.out.println(String.format("Общая сумма: %.2f ", total) + Product.sklonenie(total));
double totalPerPerson = total / countPersons;
System.out.println("Каждый человек должен заплатить: " + String.format("%.2f", totalPerPerson) + " " + Product.sklonenie(totalPerPerson) + ".");
}
}