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
39 lines (34 loc) · 1.43 KB
/
Calculator.java
File metadata and controls
39 lines (34 loc) · 1.43 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
29
30
31
32
33
34
35
36
37
38
39
import java.util.ArrayList;
/**
* Класс для расчета суммы, которую должен заплатить каждый человек
*/
public class Calculator {
int personCount; // Количество человек
ArrayList<Dish> dishList; // Список блюд
Calculator(int personCount, ArrayList<Dish> dishList) {
this.personCount = personCount;
this.dishList = dishList;
}
/**
* Считает сумму, которую должен заплатить каждый человек поровну и выводит его в консоль
*/
public void calculate() {
String pricesSum = Utils.formatPriceData(getPricesSum());
System.out.println("Общая стоимость блюд: " + pricesSum + ".");
System.out.println("Количество персон: " + personCount + ".");
String result = Utils.formatPriceData(getPricesSum() / personCount);
System.out.println("Производим расчет...\nКаждый человек должен заплатить: " + result + ".");
}
/**
* Считает общую стоимость всех блюд
*
* @return double Общая стоимость всех блюд
*/
public double getPricesSum() {
double sum = 0;
for (Dish dish : this.dishList) {
sum += dish.price;
}
return sum;
}
}