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
43 lines (39 loc) · 1.53 KB
/
Main.java
File metadata and controls
43 lines (39 loc) · 1.53 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
import java.util.InputMismatchException;
import java.util.Locale;
import java.util.Scanner;
public class Main {
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("На сколько человек разделить счёт?:");
int peopleCount;
try {
peopleCount = scanner.nextInt();
} catch (InputMismatchException ignored) {
peopleCount = -1;
}
while (peopleCount <= 1) {
scanner.nextLine();
System.out.println("Введите целое положительное число больше 1: ");
try {
peopleCount = scanner.nextInt();
} catch (InputMismatchException ignored) {
peopleCount = -1;
}
}
Calculator calculator = new Calculator(peopleCount);
String complete;
do {
calculator.addGood();
System.out.println("Добавить ещё один товар в корзину?:");
complete = scanner.next();
} while (!complete.equalsIgnoreCase("завершить"));
System.out.println("Добавленные товары:\n" + calculator.getGoods());
Double averagePerPerson = calculator.getAveragePerPerson();
System.out.printf(
Locale.US,
"%.2f %s%n",
averagePerPerson,
Formatter.conjugate((int) Math.floor(averagePerPerson))
);
}
}