forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroceryList.java
More file actions
36 lines (29 loc) · 1.32 KB
/
GroceryList.java
File metadata and controls
36 lines (29 loc) · 1.32 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
import java.util.Scanner;
class GroceryList {
public static double Product(Scanner nameProduct) {
double sum = 0.0;
StringBuilder products = new StringBuilder(("Добавить блюда")); //Обьявить блюда
while (true) {
String name;
System.out.println("Введите название блюда. Либо напишите 'Завершить'."); // Ввести название блюда
name = nameProduct.next();
if (name.equalsIgnoreCase("Завершить")) { //Подсчет итога
System.out.println(products);
break;
}
double price;
System.out.println("Введите стоимость блюда"); // Ввести стоимость
while (!nameProduct.hasNextDouble()) {
System.out.println("Введите стоимость блюда в формате: 11,11");
nameProduct.next();
}
price = nameProduct.nextDouble();
if (price > 0) {
products.append("\n").append(name).append(" по цене ").append(price);
sum += price;
System.out.println("Блюдо добавлено");
}
}
return sum;
}
}