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
55 lines (53 loc) · 2.31 KB
/
Main.java
File metadata and controls
55 lines (53 loc) · 2.31 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int countPersons;
while (true) {
System.out.println("На скольких человек необходимо разделить счёт?");
if (scanner.hasNextInt()) {
countPersons = scanner.nextInt();
scanner.nextLine();
if (countPersons > 1) {
break;
}
} else {
scanner.next();
}
System.out.println("Это некорректное значение. Попробуем еще раз?");
}
Calculator calculator = new Calculator(countPersons);
while (true) {
System.out.println("Введите наименование товара:");
String name = scanner.nextLine();
float price;
while (true) {
System.out.println("Введите стоимость товара:");
if (scanner.hasNextFloat()) {
price = scanner.nextFloat();
scanner.nextLine();
if (price > 0) {
break;
}
} else {
scanner.next();
}
System.out.println("Наверное вы ошиблись в стоимости. Попробуйте еще раз.");
}
Good good = new Good(name, price);
calculator.addGood(good);
System.out.println("Товар успешно добавлен.");
System.out.println("Хотите добавить еще товар? Введите \"Завершить\" для окончания.");
String command = scanner.nextLine();
if (command.equalsIgnoreCase("завершить")) {
break;
}
}
scanner.close();
System.out.println("Добавленные товары:\n");
System.out.println(calculator.names);
Formatter formatter = new Formatter();
System.out.println("Каждый человек должен заплатить " +
formatter.getFormattedSum(calculator.sumByPerson()));
}
}