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
62 lines (53 loc) · 2.74 KB
/
Main.java
File metadata and controls
62 lines (53 loc) · 2.74 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("На сколько человек необходимо разделить счёт?");
Scanner scanner = new Scanner(System.in);
int numberPersons;
while (true) {
if (scanner.hasNextInt()) {
numberPersons = scanner.nextInt();
if (numberPersons > 1) {
break;
} else {
System.out.println("Ошибка! Введено меньше 2. Введите корректное количество гостей. Для закрытия программы напишите \"выход\"");
}
} else {
String exit = scanner.next();
if (exit.equalsIgnoreCase("выход")) {
System.out.println("Завершена работы программы!");
return;
} else {
System.out.println("Ошибка! Введено не число. Введите корректное количество гостей. Для закрытия программы напишите \"выход\"");
scanner.nextLine();
}
}
}
Calculation calculation = new Calculation(numberPersons);
while (true) {
System.out.println("Введите название товара. Для закрытия программы напишите \"завершить\""); // можно сделать через useDelimeter(). думаю пока как обработать несколько пробелов
String product = scanner.next();
if (product.equalsIgnoreCase("завершить")) {
break;
} else {
while (true) {
System.out.println("Введите стоимость товара (руб,коп).");
try {
double price = scanner.nextDouble();
if (price > 0) {
calculation.addProduct(product, price);
break;
} else {
System.out.println("Ошибка! Введено отрицательное значение!");
}
} catch (Exception err){
System.out.println("Ошибка! Введено не число");
scanner.nextLine();
}
}
}
}
System.out.println(calculation.productList);
System.out.println(calculation.divideCheck());
}
}