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
53 lines (48 loc) · 1.4 KB
/
Formatter.java
File metadata and controls
53 lines (48 loc) · 1.4 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
42
43
44
45
46
47
48
49
50
51
52
53
public class Formatter {
String r;
// Функция вывода результата
void printResult(String result, double price){
switchPrice(price);
String output = "Добавленные товары: \n%s \nСумма на каждого - %.2f %s";
System.out.println(String.format(output, result, price, r));
}
// Функфия склонения рубля
String switchPrice(double price) {
double inPrice = Math.floor(price) % 100;
if ((inPrice >= 11) && (inPrice < 15)) {
switch ((int) inPrice) {
case 11:
case 12:
case 13:
case 14: {
r = "рублей";
break;
}
}
} else {
inPrice %= 10;
switch ((int) inPrice) {
case 0:
case 6:
case 5:
case 7:
case 8:
case 9: {
r = "рублей";
break;
}
case 1: {
r = "рубль";
break;
}
case 2:
case 3:
case 4: {
r = "рубля";
break;
}
}
}
return r;
}
}