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
65 lines (59 loc) · 2.58 KB
/
Main.java
File metadata and controls
65 lines (59 loc) · 2.58 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
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
double sum = 0;
int quantity = 0;
while (true) {
Scanner scanner = new Scanner(System.in);
System.out.println("На скольких человек необходимо разделить счёт?");
if (scanner.hasNextInt()) {
quantity = scanner.nextInt();
if (quantity < 2) {
System.out.println("Неверное значение");
} else {
break;
}
} else {
System.out.println("Неверное значение");
}
}
ArrayList<Product> productsList = new ArrayList<>();
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("Введите название товара");
String name = sc.nextLine();
if (name.trim().isEmpty()) {
System.out.println("Что-нибудь еще, кроме пустоты?");
} else {
if (name.equalsIgnoreCase("Завершить")) {
for (int i = 0; i < productsList.size(); i++) {
Product element = productsList.get(i);
System.out.println(element.name + " " + element.price);
sum += element.price;
}
String rub = Format.formatRub(sum / quantity);
System.out.printf("Итого с человека: %.2f" + rub, sum / quantity);
break;
} else {
while (true) {
Scanner sc1 = new Scanner(System.in);
System.out.println("Введите цену");
if (sc1.hasNextDouble()) {
double price = sc1.nextDouble();
Product newProduct = new Product(name, price);
productsList.add(newProduct);
System.out.println("Добавленные товары: ");
for (Product k : productsList) {
System.out.println(k.name);
}
break;
} else {
System.out.println("Неверное значение цены");
}
}
}
}
}
}
}