Repository navigation
Expand file tree
/
Copy pathProducts.java
More file actions
64 lines (63 loc) · 3.27 KB
/
Copy pathProducts.java
File metadata and controls
64 lines (63 loc) · 3.27 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
import java.util.InputMismatchException;
import java.util.Scanner;
public class Products {
static String strProducts = "";
static double sum = 0;
static double productPrice;
static void productCount() {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Хотите добавить товар?");
String productInput = scanner.next();
switch (productInput.toLowerCase()) {
case "да":
while (true) {
System.out.println("Введите название товара.");
String productName = scanner.next();
strProducts = strProducts.concat("\n").concat(productName);
while (true) {
System.out.println("Введите стоимость товара.");
try {
productPrice = scanner.nextDouble();
}catch (InputMismatchException b){
System.out.println("Введено не число.");
scanner.nextLine();
}
if (productPrice > 0) {
break;
} else if (productPrice < 0) {
System.out.println("Стоимость не может быть отрицательной!");
}
}
System.out.println("Товар добавлен!");
sum = sum + productPrice;
System.out.println("Хотите добавить еще товар? (Введите \"Завершить\" ,чтобы завершить процесс добавления товаров.)");
String productInput2 = scanner.next();
switch (productInput2.toLowerCase()) {
case "да":
break;
case "нет":
return;
case "завершить":
return;
default:
while (true) {
System.out.println("Введите \"Да\" ,чтобы добавить товар.\nВведите \"Завершить\" ,чтобы завершить процесс добавления товаров.");
String productInput3 = scanner.next();
if (productInput3.equalsIgnoreCase("да")) {
break;
} else if (productInput3.equalsIgnoreCase("Завершить")) {
return;
} else {
}
}
}
}
case "нет":
return;
default:
System.out.println("Введите да или нет!");
}
}
}
}