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
49 lines (38 loc) · 1.45 KB
/
Main.java
File metadata and controls
49 lines (38 loc) · 1.45 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
public class Main {
private static final int MIN_PEOPLE_COUNT = 2;
private static final String FINISH_COMMAND = "Завершить";
static int readPersonsCount() {
int personsCount;
while (true) {
personsCount = TerminalReader.readInt(
String.format(
"На скольких человек разделить счет ? (значение должно быть >=%d)",
MIN_PEOPLE_COUNT
)
);
if (personsCount < MIN_PEOPLE_COUNT) {
System.out.printf(
"Значение должно быть >=%d !%n",
MIN_PEOPLE_COUNT
);
} else {
break;
}
}
return personsCount;
}
public static void main(String[] args) {
int personsCount = readPersonsCount();
Calculator calculator = new Calculator(personsCount);
while (true) {
Product product = Product.read();
calculator.add(product);
String command = TerminalReader.readString("Хотите добавить еще товар ? Если нет, введите \"завершить\".");
if (command.equalsIgnoreCase(FINISH_COMMAND)) {
break;
}
}
calculator.showAllProducts();
calculator.showSumByPerson();
}
}