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
35 lines (32 loc) · 1.05 KB
/
Calculator.java
File metadata and controls
35 lines (32 loc) · 1.05 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
public class Calculator {
double allPriceSum;
String basket;
public void addGoods(String newGoods, double goodsPrice) {
if (this.basket == null) {
this.basket = newGoods;
} else {
this.basket = this.basket + "\n" + ((this.basket.compareToIgnoreCase(newGoods) != 0) ? newGoods : "");
}
this.allPriceSum = this.allPriceSum + goodsPrice;
}
public String correctStringCurrency(int peopleCount) {
double lastValue = (allPriceSum / peopleCount) % 100 / 10;
String retValue;
if ((int)lastValue == 1) {
return "рублей";
} else {
switch ((int) Math.floor((allPriceSum / peopleCount) % 10)) {
case 1:
retValue = "рубль";
break;
case 2, 3, 4:
retValue = "рубля";
break;
default:
retValue = "рублей";
break;
}
}
return retValue;
}
}