forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormatter.java
More file actions
26 lines (23 loc) · 757 Bytes
/
Formatter.java
File metadata and controls
26 lines (23 loc) · 757 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
import java.util.List;
public class Formatter {
public static String getCaseRub(double sumRub){
if(sumRub%10 == 1){
return "рубль";
}
else if(sumRub%10 >= 2 && sumRub%10 <= 4){
return "рубля";
}
else{
return "рублей";
}
}
public static String getFinalSum(int countPerson, List<Product> products){
double sumPerPerson = 0;
double sumAllProducts = 0;
for(Product p : products){
sumAllProducts += p.getPrice();
}
sumPerPerson = sumAllProducts / countPerson;
return String.format("Каждый должен заплатить %.2f %s", sumPerPerson, getCaseRub(sumPerPerson));
}
}