Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
47 lines (40 loc) · 1.57 KB
/
Copy pathMain.java
File metadata and controls
47 lines (40 loc) · 1.57 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
print("На сколько человек необходимо разделить счёт?");
Scanner scanner = new Scanner(System.in);
Scanner scannerForCalc = new Scanner(System.in);
int quantityUser = quantityUserChecker(enterQuantityUser(scanner), scanner);
Calc calc = new Calc(scannerForCalc);
calc.addProductToCalc();
calc.printProducts();
calc.printAmountPerPerson(quantityUser);
}
private static int enterQuantityUser(Scanner scanner) {
try {
return scanner.nextInt();
} catch (Exception e) {
print("некорректное значение! пожалуйста, введите целое число больше 1");
return enterQuantityUser(new Scanner(System.in));
}
}
private static int quantityUserChecker(int quantityUser, Scanner scanner) {
while (true) {
if (quantityUser == 1) {
print("Нет смысла делить счет на одного :)");
quantityUser = enterQuantityUser(scanner);
}
if (quantityUser <= 0) {
print("Некорректное значение :(");
quantityUser = enterQuantityUser(scanner);
}
if (quantityUser > 1) {
break;
}
}
return quantityUser;
}
private static void print(String message) {
System.out.println(message);
}
}