Repository navigation
Expand file tree
/
Copy pathProduct.java
More file actions
51 lines (45 loc) · 1.66 KB
/
Copy pathProduct.java
File metadata and controls
51 lines (45 loc) · 1.66 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
import java.util.ArrayList;
public class Product {
String name;
double price;
double sum = 0;
ArrayList<String> listPro = new ArrayList<>();
public void products() {
System.out.println("Укажите название и стоимость каждого товара?");
name = "";
boolean isProductInputFinished = false;
while (!isProductInputFinished) {
System.out.println("Название товара:");
name = Main.scanner.next();
if (name.equalsIgnoreCase("завершить")) {
isProductInputFinished = true;
continue;
}
listPro.add(name);
priceSum();
System.out.println("Товар успешно добавлен!\n----------");
System.out.println("Хотите добавить еще один товар? Если нет, то введите - Завершить");
}
}
private void priceSum() {
System.out.println("Стоимость товара = ");
String priceStr = Main.scanner.next();
try {
price = Double.parseDouble(priceStr);
} catch (Exception e) {
price = -1;
}
if (price < 0.0) {
System.out.println("Введите корректную стоимость товара:");
priceSum();
return;
}
sum = sum + price;
}
public void shoplist() {
System.out.println("----------\nДобавленные товары:");
for (int i = 0; i < listPro.size(); i++) {
System.out.println(listPro.get(i));
}
}
}