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
31 lines (24 loc) · 872 Bytes
/
Calculator.java
File metadata and controls
31 lines (24 loc) · 872 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
import java.util.ArrayList;
public class Calculator {
private ArrayList<Product> listOfProducts = new ArrayList<>();
public void addNewProduct(Product newProduct) {
listOfProducts.add(newProduct);
}
public double calculateSumOfAllPrices() {
double sum = 0;
for (Product product : this.listOfProducts) {
sum += product.price;
}
return sum;
}
public double calculateSumPerPerson(double sum, int numberOfPeople) {
return sum / numberOfPeople;
}
public void printListOfAddedProducts() {
System.out.println("Добавленные товары:");
for (Product product : this.listOfProducts) {
System.out.println(product.name + " - " + product.price + " " +
RubleFormatter.getCorrectFormOfRuble(product.price));
}
}
}