forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddProduct.java
More file actions
70 lines (61 loc) · 2.7 KB
/
addProduct.java
File metadata and controls
70 lines (61 loc) · 2.7 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
66
67
68
69
70
import java.util.ArrayList;
import java.util.Scanner;
public class addProduct {
public static ArrayList<String> addProducts(Scanner scanner) {
ArrayList<String> productsArrayList = new ArrayList<>();
scanner.nextLine();
while (true) {
System.out.println();
System.out.println("Введите название товара");
boolean checkLine = true;
while (checkLine) {
String product = scanner.nextLine();
if (!product.isEmpty()) {
productsArrayList.add(product);
checkLine = false;
} else {
System.out.println("Ошибка! Введите название товара");
}
}
System.out.println("Введите стоимость товара");
boolean check = true;
while (check){
if (scanner.hasNextDouble()){
double cost = scanner.nextDouble();
if (cost >= 0) {
productsArrayList.add(String.valueOf(cost));
check = false;
} else {
System.out.println("Вы ввели отрицательное число! Введите стоимость товара");
}
} else {
System.out.println("Некорректный ввод данных! Введите стоимость товара");
scanner.nextLine();
}
}
scanner.nextLine();
System.out.println("Товар успешно добавлен!");
System.out.println("-----------------------");
System.out.println();
System.out.println("Хотите продолжить? Для завершения ввода используйте команду 'завершить'");
String yesOrBreak = scanner.nextLine();
if (yesOrBreak.equalsIgnoreCase("завершить")){
break;
}
}
return productsArrayList;
}
public static int howManyPeople(Scanner scanner) {
System.out.println("На какое количество людей необходимо разделить счет?");
boolean check = true;
while (check){
if (scanner.hasNextInt()) {
check = false;
} else {
System.out.println("Ошибка! Это некорректное значение для подсчёта!");
scanner.nextLine();
}
}
return scanner.nextInt();
}
}