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
36 lines (29 loc) · 912 Bytes
/
Calculator.java
File metadata and controls
36 lines (29 loc) · 912 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
30
31
32
33
34
35
36
import java.util.ArrayList;
public class Calculator {
ArrayList<Product> listProduct = new ArrayList<>();
public void addProduct(Product product) {
listProduct.add(product);
}
public double amountGuest(int n) {
double sum = 0;
for (Product i : listProduct) {
sum += i.getPrice();
}
return sum / n;
}
public double totalAmount() {
double sum = 0;
for (Product i : listProduct) {
sum += i.getPrice();
}
return sum;
}
public void printListProduct() {
int index = 1;
System.out.println("Добавленные товары:\n-------------------");
for (Product i : listProduct) {
System.out.println(index++ + ": " + i.getName() + " " + Formatter.floorCount(i.getPrice()));
}
System.out.println("-------------------");
}
}