Repository navigation
Expand file tree
/
Copy pathProducts.java
More file actions
58 lines (38 loc) · 1.8 KB
/
Copy pathProducts.java
File metadata and controls
58 lines (38 loc) · 1.8 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
import java.util.Scanner;
public class Products {
double priceProduct;// стоимость товара
String nameProduct;// наименование товара
static double totalPrice;// общая сумма
String listProduct="Добавленные товары:";// список товаров
Scanner scan = new Scanner(System.in);
public void TotalproductAndPrice() {
while (true) {
System.out.println("Введите наименование товара");
nameProduct = scan.next();
System.out.println("Товар добавлен в калькулятор");
listProduct += "\n"+nameProduct;
System.out.println("Введите стоимость товара в формате рубли,копейки");
while (true) {
if (scan.hasNextDouble()) {
priceProduct = scan.nextDouble();
if (priceProduct <= 0) {
System.out.println("Стоимость д.б. больше 0, повторите ввод");
} else {
break;
}
} else {
System.out.println("Введите корректное значение в цифрах");
scan.next();
}
}
scan.nextLine();
totalPrice += priceProduct;
System.out.println("Желаете добавить еще товар? Если нет, то напишите \"завершить\"");
String input = scan.nextLine();
if (input.equalsIgnoreCase("завершить")) {
break;
}
}
System.out.println(listProduct);
}
}