forked from Yandex-Practicum/Java-Module-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.java
More file actions
46 lines (40 loc) · 1.96 KB
/
Order.java
File metadata and controls
46 lines (40 loc) · 1.96 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
import java.util.Scanner;
import java.util.ArrayList;
public class Order {
Bill bill = new Bill();
ArrayList<Dish> dishList = new ArrayList<>();
// добавить блюдо в заказ
void addDish(Dish aDish) {
dishList.add(aDish);
bill.addToBill(aDish.price);
System.out.printf("В заказ добавлено блюдо \"%s\" стоимостью %s %s", aDish.name, Utils.toStringCustomFormat(aDish.price), Utils.getRoubleSuffix(aDish.price));
System.out.println();
}
// распечатать заказ
public void printOrder() {
System.out.println("Ваш заказ. Добавленные товары:");
for (Dish d: dishList) {
d.printDish();
}
}
// создать список блюд заказа
public void inputDishList() {
Scanner scanner = new Scanner(System.in);
String sDishName, sDishPrice;
do {
do {
System.out.print("Введите непустое наименование блюда: ");
sDishName = scanner.next();
} while (!Dish.isCorrectName(sDishName));
while(true) {
System.out.print("Введите стоимость блюда в формате рубли.копейки: ");
sDishPrice = scanner.next();
if (Dish.isCorrectPrice(sDishPrice))
break;
System.out.println("Некорректная стоимость блюда");
}
addDish(new Dish(sDishName, Double.parseDouble(sDishPrice))); // добавляем блюдо в заказ
System.out.println("Добавим еще одно блюдо в заказ? Введите \"Завершить\", чтобы отказаться или любой символ, чтобы продолжить");
} while (!scanner.next().equalsIgnoreCase("завершить"));
}
}