forked from Yandex-Practicum/Java-Module-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoodCalculator.java
More file actions
47 lines (38 loc) · 1.16 KB
/
GoodCalculator.java
File metadata and controls
47 lines (38 loc) · 1.16 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
public class GoodCalculator {
String goodName;
String goodSumName = "Добавленные товары:";
double goodPrice;
double goodSumPrice;
GoodCalculator() {
String goodName = "";
double goodPrice;
double goodSumPrice = 0.0;
}
void addGood(String goodName, double goodPrice) {
this.goodSumName = goodSumName + "\n" + goodName + ": " + goodPrice + " " + rubleEnding(goodPrice);
this.goodSumPrice += goodPrice;
}
String rubleEnding(double rubleValue) {
int rubleValueInt = (int) (Math.floor(rubleValue));
String result;
if ((rubleValueInt % 100 > 10) && (rubleValueInt % 100 < 20)) {
result = "рублей";
}
else {
switch (rubleValueInt % 10) {
case 1:
result = "рубль";
break;
case 2:
case 3:
case 4:
result = "рубля";
break;
default:
result = "рублей";
break;
}
}
return result;
}
}