forked from Yandex-Practicum/Java-Module-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBillCalculator.java
More file actions
29 lines (24 loc) · 994 Bytes
/
BillCalculator.java
File metadata and controls
29 lines (24 loc) · 994 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
28
29
import java.util.ArrayList;
public class BillCalculator {
int personsNumber;
double sumPrice;
ArrayList<Product> products = new ArrayList<>();
public BillCalculator(int personsNumber) {
this.personsNumber = personsNumber;
}
public void addProduct(String name, double price) { // Добавление продукта в список
products.add(new Product(name, price));
sumPrice += price;
}
public void printProducts() { // Вывод списка продуктов
int size = products.size();
System.out.println("Добавленные товары:");
for (int i = 0; i < size; i++) {
products.get(i).printProduct();
}
System.out.println("Итого: " + sumPrice + Helpers.getRuble(sumPrice));
}
public double calculateBill() { // Расчет суммы к оплате каждым человеком
return sumPrice/personsNumber;
}
}