forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.java
More file actions
46 lines (40 loc) · 1.18 KB
/
Utils.java
File metadata and controls
46 lines (40 loc) · 1.18 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
public class Utils {
public static String getRubleInRightCase(int numeric){
//--- Остаток от деления на 100
int remOnDiv100 = (numeric % 100);
//--- от 10 до 20 всегда рублей
if (remOnDiv100 >= 10 && remOnDiv100 <= 20) {
return "рублей";
}
int remOnDiv10 = remOnDiv100 % 10;
switch (remOnDiv10){
case 1:
return "рубль";
case 2:
case 3:
case 4:
return "рубля";
default:
return "рублей";
}
}
public static boolean isCorrectPeopleCount(String value){
try {
Integer.parseInt(value);
} catch (Exception e) {
return false;
}
return !(Integer.parseInt(value) <= 1);
}
public static boolean isCorrectPrice(String value){
try {
Float.parseFloat(value);
} catch (Exception e) {
return false;
}
return !(Float.parseFloat(value) < 0);
}
public static boolean isCorrectTitle(String value){
return !value.trim().equals("");
}
}