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
39 lines (32 loc) · 964 Bytes
/
Calculator.java
File metadata and controls
39 lines (32 loc) · 964 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
39
public class Calculator {
public double calculate(int pplCount,double amountReceipt){
double result = amountReceipt/(double) pplCount;
return mathFloor(result);
}
public double conversionSum(double price){
return mathFloor(price);
}
double mathFloor(double sum){
return Math.floor(100*sum)/100.0;
}
public String formatSum(double price){
int partOfPrice = ((int) price) % 100;
if (Double.compare(partOfPrice,14)>0) {
partOfPrice = ((int) partOfPrice) % 10;
}
String nameRub = "";
switch (partOfPrice){
case 1:
nameRub = "рубль";
break;
case 2:
case 3:
case 4:
nameRub = "рубля";
break;
default:
nameRub = "рублей";
}
return String.format("%.2f %s",price, nameRub);
}
}