forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductPrinter.java
More file actions
41 lines (35 loc) · 1.26 KB
/
ProductPrinter.java
File metadata and controls
41 lines (35 loc) · 1.26 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
40
41
import java.util.ArrayList;
import java.util.Iterator;
public class ProductPrinter {
public void print(ArrayList<Product> list, double sum) {
System.out.println("Добавленные товары:");
Iterator<Product> iterator = list.iterator();
while (iterator.hasNext()) {
Product product = iterator.next();
System.out.println(product.name + " " + product.price);
}
System.out.println(String.format("Сумма на одного человека составляет: %.2f " + currencyFormat(sum), sum));
}
public String currencyFormat(double price) {
String ending;
int intPrice = (int) (price);
int remainderTen = (intPrice % 10);
int remainderHundred = (intPrice % 100);
if (remainderHundred >= 11 && remainderHundred <= 19) {
ending = "рублей";
} else {
switch (remainderTen) {
case 1:
ending = "рубль";
break;
case 2, 3, 4:
ending = "рубля";
break;
default:
ending = "рублей";
break;
}
}
return ending;
}
}