forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductList.java
More file actions
31 lines (26 loc) · 1.43 KB
/
ProductList.java
File metadata and controls
31 lines (26 loc) · 1.43 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
import java.util.ArrayList;
import java.util.Scanner;
class ProductList {
public static ArrayList<Product> inputOrders() {
ArrayList<Product> products = new ArrayList<>();
while (true) {
try {
Scanner scanner = new Scanner(System.in);
System.out.println("Введите название товара:");
String orderName = scanner.next();
System.out.println("Введите стоимость товара:");
double orderPrice = scanner.nextFloat();
if(orderPrice <= 0) {
System.out.println("Некорректная сумма!");
continue;
}
products.add(new Product(orderName, orderPrice));
System.out.println("Товар успешно добавлен!\n\nХотите добавить ещё товар?\n1. Для продолжения напишите любой символ\n2. Для отмены напишите \"Завершить\" в любом регистре.");
String action = scanner.next();
if(action.equalsIgnoreCase("Завершить")) return products;
} catch (Exception e) {
System.out.println("Ошибка: некорректный ввод");
}
}
}
}