Repository navigation
Expand file tree
/
Copy pathMenu.java
More file actions
51 lines (40 loc) · 2.05 KB
/
Copy pathMenu.java
File metadata and controls
51 lines (40 loc) · 2.05 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
import java.util.Scanner;
class Menu {
String allProduct = "";
double allPrice;
double priceProduct;
Scanner scan = new Scanner(System.in);
public void resalts() {
while (true) {
System.out.println("Введите название товара");
String product = scan.next();
if (product.equalsIgnoreCase("Завершить")) {
System.out.println("Добавление товара завершено");
break;
}
while (true) {
System.out.println("Введите стоимость товара в формате 00,00");
while (!scan.hasNextDouble()) {
scan.next();
System.out.println("Не верный формат ввода. Введите стоимость в цифрах формата 00,00");
}
while (true) {
priceProduct = scan.nextDouble();
if (priceProduct > 0) {
break;
} else if (priceProduct < 0) {
System.out.println("Вы ввели не верный формат стоимости");
} else {
System.out.println("Введите верный формат");
}
}
System.out.println("Товар добавлен в счет. \nТовар: " + product + " Цена: " + priceProduct + "\nЕсли вы хотите продолжить выбор, то введите название товара \nЕсли выхотите завершить выбор товара, то введите команду \"Завершить\"");
allProduct += product + "\n";
allPrice = allPrice + priceProduct;
break;
}
}
System.out.println("Весь товар:" + "\n" + allProduct);
System.out.println("Полная стоимость " + allPrice);
}
}