-
Notifications
You must be signed in to change notification settings - Fork 299
Expand file tree
/
Copy pathMain.java
More file actions
78 lines (62 loc) · 2.66 KB
/
Main.java
File metadata and controls
78 lines (62 loc) · 2.66 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package ru.practicum.dinner;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
static DinnerConstructor dc;
static Scanner scanner;
public static void main(String[] args) {
dc = new DinnerConstructor();
scanner = new Scanner(System.in);
while (true) {
printMenu();
String command = scanner.nextLine();
switch (command) {
case "1":
addNewDish();
break;
case "2":
generateDishCombo();
break;
case "3":
return;
default:
System.out.println("Invalid command");
break;
}
}
}
private static void printMenu() {
System.out.println("Выберите команду:");
System.out.println("1 - Добавить новое блюдо");
System.out.println("2 - Сгенерировать комбинации блюд");
System.out.println("3 - Выход");
}
private static void addNewDish() {
System.out.println("Введите тип блюда:");
String dishType = scanner.nextLine();
System.out.println("Введите название блюда:");
String dishName = scanner.nextLine();
dc.addDish(dishType, dishName);
}
private static void generateDishCombo() {
System.out.println("Начинаем конструировать обед...");
System.out.println("Введите количество наборов, которые нужно сгенерировать:");
int numberOfCombos = scanner.nextInt();
while (numberOfCombos <= 0) {
System.out.println("Пожалуйста, введите положительное целое число.");
numberOfCombos = scanner.nextInt();
}
scanner.nextLine(); // Consume newline
System.out.println("Вводите типы блюда, разделяя символом переноса строки (enter). Для завершения ввода введите пустую строку");
ArrayList<String> dishTypes = new ArrayList<>();
String nextItem = scanner.nextLine();
while (!nextItem.isEmpty()) {
dishTypes.add(nextItem);
nextItem = scanner.nextLine();
}
ArrayList<ArrayList<String>> combinations = dc.generateCombinations(numberOfCombos, dishTypes);
for (ArrayList<String> combo : combinations) {
System.out.println("Комбинация: " + combo);
}
}
}