forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeclension.java
More file actions
29 lines (23 loc) · 847 Bytes
/
Declension.java
File metadata and controls
29 lines (23 loc) · 847 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
public class Declension {
//Склонялка + вывод результата
public String toIncline(Calculator calculator) {
int preLastDigit = (int) Math.floor(calculator.share) % 100 / 10;
if (preLastDigit == 1) {
return "рублей";
}
switch ((int) Math.floor(calculator.share) % 10) {
case 1:
return "рубль";
case 2:
case 3:
case 4:
return "рубля";
default:
return "рублей";
}
}
public void showResult(Calculator calculator){
String finalMessage = String.format("С каждого гостя %.2f %s.\nОплата карточкой?", calculator.share, toIncline(calculator));
System.out.println(finalMessage);
}
}