forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormatter.java
More file actions
57 lines (55 loc) · 1.93 KB
/
Formatter.java
File metadata and controls
57 lines (55 loc) · 1.93 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
47
48
49
50
51
52
53
54
55
56
57
import java.util.Scanner;
public class Formatter {
public static void main(String[] args) {
}
public static String GetDeclinationRub(int num) {
var penultimateDigit = num % 100 / 10;
if (penultimateDigit == 1)
{
return "рублей.";
}
switch (num % 10)
{
case 1:
return "рубль.";
case 2:
case 3:
case 4:
return "рубля.";
default:
return "рублей.";
}
}
public static boolean checksForInput(String input) {
boolean proverka = false;
try {
int people = Integer.parseInt(input);
if (people == 1) {
System.out.println("Количество людей должно быть больше одного. Повторите ввод.");
} else if (people < 1) {
System.out.println("Некорректное значение для подсчёта. Повторите ввод.");
}else {
proverka = true;
}
} catch (NumberFormatException e) {
System.out.println("Некорректное значение для подсчёта. Повторите ввод.");
proverka = false;
}
return proverka;
}
public static boolean checksForPrice(String input){
boolean proverka = false;
try {
Double cost = Double.parseDouble(input);
if (cost <= 0) {
System.out.println("Некоректное значение, повторите ввод.");
} else {
proverka = true;
}
} catch (NumberFormatException e) {
System.out.println("Некорректное значение. Повторите ввод.");
proverka = false;
}
return proverka;
}
}