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
29 lines (25 loc) · 916 Bytes
/
Formatter.java
File metadata and controls
29 lines (25 loc) · 916 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
import java.util.ArrayList;
public class Formatter {
static String getFormattedOutput(float price) {
int resultInt = (int) price;
String rubles;
if (resultInt % 100 <= 19 && resultInt % 100 >= 11) {
rubles = "рублей";
} else if (resultInt % 10 >= 2 && resultInt % 10 <= 4) {
rubles = "рубля";
} else if (resultInt % 10 == 1) {
rubles = "рубль";
} else {
rubles = "рублей";
}
return String.format("С каждого по %.2f %s", price, rubles);
}
static String getFormattedGoods(ArrayList<Good> goods) {
StringBuilder result = new StringBuilder();
result.append("Добавленные товары:\n");
for (Good good : goods) {
result.append(good.name).append('\n');
}
return result.toString().trim();
}
}