forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDish.java
More file actions
56 lines (39 loc) · 1.7 KB
/
Dish.java
File metadata and controls
56 lines (39 loc) · 1.7 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
import java.text.MessageFormat;
import java.util.Scanner;
public class Dish {
String allNameProducts = " ";
float allCost = 0;
public String addDish() {
System.out.println("Введите название блюда: ");
Scanner scanner = new Scanner(System.in);
while (true) {
String nameProducts = (scanner.nextLine());
if ("Завершить".equalsIgnoreCase(nameProducts)) {
return String.format("Список добавленных блюд: %s", allNameProducts);
} else {
addCost();
allNameProducts = MessageFormat.format("{0}\n{1}", allNameProducts, nameProducts);
System.out.println(nameProducts + "\n" + "Добавлено!\n\nВведите название нового блюда или Завершить");
}
}
}
public void addCost() {
Scanner scanner = new Scanner(System.in);
System.out.println("Введите стоимость блюда: ");
while (true) {
if (scanner.hasNextFloat()) {
float cost = scanner.nextFloat();
if (cost > 0) {
allCost += cost;
break;
} else {
System.out.println("Некорректная стоимость\nВведите в формате рублей.копеек");
scanner.nextLine();
}
} else {
System.out.println("Введите число");
scanner.nextLine();
}
}
}
}