forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
38 lines (31 loc) · 915 Bytes
/
Calculator.java
File metadata and controls
38 lines (31 loc) · 915 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
30
31
32
33
34
35
36
37
38
public class Calculator {
String names = "";
int people;
double valueResult;
Calculator(int people) {
this.people = people;
}
void addMember(Product product) {
valueResult += product.productValue;
names += product.productName + "\n";
}
public String Cost() {
double sum = valueResult / people;
var rubles = Math.floor(sum);
var suffix = getSuffix(rubles);
return String.format("%.2f", sum) + " рубл" + suffix;
}
public static String getSuffix(double rubles) {
double numb1 = rubles % 100;
double numb2 = rubles % 10;
if (numb1 >= 11 && numb1 <= 14) {
return "ей";
} else if (numb2 == 1) {
return "ь";
} else if (numb2 == 2 || numb2 == 3 || numb2 == 4) {
return "я";
} else {
return "ей";
}
}
}