forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPricePlurals.java
More file actions
23 lines (20 loc) · 974 Bytes
/
PricePlurals.java
File metadata and controls
23 lines (20 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class PricePlurals {
private static final int RADIX = 10;
private static final int REMAINDER_ONE = 1;
private static final int REMAINDER_TWO = 2;
private static final int REMAINDER_THREE = 3;
private static final int REMAINDER_FOUR = 4;
private static final int ELEVEN = 11;
private static final int TWELVE = 12;
private static final int THIRTEEN = 13;
private static final int FOURTEEN = 14;
public String getSuffix(float price) {
final int roundedPrice = (int) price;
final int lastDigit = roundedPrice % RADIX;
if (lastDigit == REMAINDER_ONE && roundedPrice != ELEVEN) return "рубль";
if (lastDigit == REMAINDER_TWO && roundedPrice != TWELVE) return "рубля";
if (lastDigit == REMAINDER_THREE && roundedPrice != THIRTEEN) return "рубля";
if (lastDigit == REMAINDER_FOUR && roundedPrice != FOURTEEN) return "рубля";
return "рублей";
}
}