forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSplitCheck.java
More file actions
28 lines (28 loc) · 1.02 KB
/
SplitCheck.java
File metadata and controls
28 lines (28 loc) · 1.02 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
public class SplitCheck {
public static void formatter(){
double split = Main.totalPrice / Main.amountPeople;
String format = "Каждый человек должен заплатить поровну, а именно: %.2f %s";
int roundedSplit = (int)Math.floor(split);
int preLastDigit = roundedSplit % 100 / 10;
int lastDigit = roundedSplit % 10;
if (preLastDigit == 1){
String rubles = "рублей";
System.out.println(String.format(format, split, rubles));
} else {
String rubles;
switch (lastDigit) {
case 1:
rubles = "рубль";
break;
case 2:
case 3:
case 4:
rubles = "рубля";
break;
default:
rubles = "рублей";
break;
}System.out.println(String.format(format, split, rubles));
}
}
}