Repository navigation
Expand file tree
/
Copy pathChecking.java
More file actions
56 lines (48 loc) · 1.86 KB
/
Copy pathChecking.java
File metadata and controls
56 lines (48 loc) · 1.86 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
public class Checking {
public static boolean isInt(String input) {
if (input == null || input.isEmpty()) {
System.out.println("Нулевая строка! Введите числовое значение:");
return false;
}
try {
Integer.parseInt(input);
return true;
} catch (NumberFormatException e) {
System.out.println("Должно быть указано числовое значение! Пожалуйста повторите ввод:");
}
return false;
}
public static boolean isNotEmpty(String input) {
if (input == null || input.isEmpty()) {
System.out.print("Нулевая строка! ");
return false;
}
return true;
}
public static boolean isDouble(String input) {
if (input == null || input.isEmpty()) {
System.out.print("Нулевая строка! ");
return false;
}
try {
Double.parseDouble(input);
if (input.indexOf('.') != -1) {
String[] splitter = input.split("\\.");
if (splitter[1].length() > 2) {
System.out.print("Количество копеек не может быть больше 100! ");
return false;
} else {
return true;
}
} else {
return true;
}
} catch (NumberFormatException e) {
System.out.print("Должно быть указано числовое значение! ");
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.print("Формат введенной стоимости не соответствует 'рубли.копейки'! ");
}
return false;
}
}