forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
81 lines (70 loc) · 2.99 KB
/
Main.java
File metadata and controls
81 lines (70 loc) · 2.99 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("На сколько людей необходимо разделить счет?");
int users = getInput();
calculate();
cheque(users);
}
public static int getInput() {
Scanner scanner = new Scanner(System.in);
int users;
while (true) {
if (scanner.hasNextInt()) {
users = scanner.nextInt();
if (users == 1) {
System.out.println("Делить нечего");
break;
}
if (users <= 1) {
System.out.println("Ошибка, введите число повторно");
scanner.nextLine();
}
if (users > 1) {
System.out.println("Делим счет на " + users);
break;
}
}
else {
System.out.println("Введите корректное число");
scanner.nextLine();}
}
return users;
}
public static void calculate() {
Scanner scanner = new Scanner(System.in);
Calculator calculator = new Calculator();
while (true) {
System.out.println("Введите название товара или 'Завершить' для завершения работы калькулятора");
String productName = scanner.nextLine();
if (productName.equalsIgnoreCase("Завершить")) {
break;
}
while (true) {
System.out.println("Введите стоимость товара");
if (scanner.hasNextDouble()) {
double productPrice = scanner.nextDouble();
if (productPrice > 0) {
System.out.println("Товар успешно добавлен в калькулятор.");
scanner.nextLine();
Items items = new Items(productPrice, productName);
calculator.productsSum(items);
calculator.addNewProducts(items);
break;
} else {
System.out.println("Некорректный ввод"); // ввод отрицательного числа
scanner.nextLine();
}
} else {
System.out.println("Некорректный ввод,введите числовое значение "); // ввод нечислового значения
scanner.nextLine();
}
}
}
}
public static void cheque(int users) {
Calculator calculator = new Calculator();
Payment payment = new Payment(calculator.chequePerPerson(),users);
payment.paymentPerPerson();
}
}