forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormat.java
More file actions
26 lines (22 loc) · 795 Bytes
/
Format.java
File metadata and controls
26 lines (22 loc) · 795 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
import static java.lang.Math.floor;
public class Format {
public float money(int people, float sum){
float result = sum / Float.parseFloat(String.valueOf(people));
return result;
}
public String ruble(float floatPrice){
int price = (int) (floatPrice * 100);
price = price /100 % 100;
if (price > 20)
price %= 10;
else if (price > 5) return "рублей";
else price %= 10;
if (price == 1)return "рубль";
else if (price < 5 && price > 0) return "рубля";
else return "рублей";
}
public String endString(float cash) {
String endLine = String.format("Каждый должен оплатить %.2f %s", cash, ruble(cash));
return endLine;
}
}