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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
| import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
// Класс для хранения информации о растениях
class Plant {
private String name;
private String soil;
private String origin;
private Map<String, String> visualParameters;
private Map<String, String> growingTips;
private String multiplying;
public Plant(String name, String soil, String origin, Map<String, String> visualParameters, Map<String, String> growingTips, String multiplying) {
this.name = name;
this.soil = soil;
this.origin = origin;
this.visualParameters = visualParameters;
this.growingTips = growingTips;
this.multiplying = multiplying;
}
public String getName() {
return name;
}
public String getSoil() {
return soil;
}
public String getOrigin() {
return origin;
}
public Map<String, String> getVisualParameters() {
return visualParameters;
}
public Map<String, String> getGrowingTips() {
return growingTips;
}
public String getMultiplying() {
return multiplying;
}
@Override
public String toString() {
return name + " (soil: " + soil + ", origin: " + origin + ")";
}
}
// Класс для хранения информации об оранжерее и его растениях
class Greenhouse {
private List<Plant> plantList;
public Greenhouse() {
this.plantList = new ArrayList<>();
}
public void addPlant(Plant plant) {
plantList.add(plant);
System.out.println(plant.getName() + " added to the greenhouse.");
}
public void removePlant(Plant plant) {
plantList.remove(plant);
System.out.println(plant.getName() + " removed from the greenhouse.");
}
public Plant getPlantByName(String name) {
for (Plant plant : plantList) {
if (plant.getName().equalsIgnoreCase(name)) {
return plant;
}
}
return null;
}
public List<Plant> getPlantsBySoilType(String soilType) {
List<Plant> plants = new ArrayList<>();
for (Plant plant : plantList) {
if (plant.getSoil().equalsIgnoreCase(soilType)) {
plants.add(plant);
}
}
return plants;
}
public List<Plant> getAllPlants() {
return plantList;
}
}
// Класс для хранения информации о пользователях
class User {
private String username;
private String password;
private boolean isAdmin;
public User(String username, String password, boolean isAdmin) {
this.username = username;
this.password = password;
this.isAdmin = isAdmin;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public boolean isAdmin() {
return isAdmin;
}
}
public class GreenhouseApp {
private static final String ADMIN_USERNAME = "admin";
private static final String ADMIN_PASSWORD = "admin123";
private static Greenhouse greenhouse = new Greenhouse();
private static List<User> users = new ArrayList<>();
public static void main(String[] args) {
// Добавление пользователей
users.add(new User("user1", "password1", false));
users.add(new User("user2", "password2", false));
users.add(new User(ADMIN_USERNAME, ADMIN_PASSWORD, true));
// Добавление растений в оранжерею
Map<String, String> visualParameters1 = new HashMap<>();
visualParameters1.put("stemColor", "green");
visualParameters1.put("leafColor", "green");
visualParameters1.put("size", "medium");
Map<String, String> growingTips1 = new HashMap<>();
growingTips1.put("temperature", "20-25");
growingTips1.put("light", "tolerant");
growingTips1.put("watering", "200");
Plant plant1 = new Plant("Plant1", "podzolic", "Europe", visualParameters1, growingTips1, "seeds");
greenhouse.addPlant(plant1);
Map<String, String> visualParameters2 = new HashMap<>();
visualParameters2.put("stemColor", "brown");
visualParameters2.put("leafColor", "green");
visualParameters2.put("size", "small");
Map<String, String> growingTips2 = new HashMap<>();
growingTips2.put("temperature", "25-30");
growingTips2.put("light", "tolerant");
growingTips2.put("watering", "150");
Plant plant2 = new Plant("Plant2", "gravelly", "Asia", visualParameters2, growingTips2, "cuttings");
greenhouse.addPlant(plant2);
// Вход в систему
User currentUser = login();
if (currentUser == null) {
System.out.println("Invalid username or password.");
return;
}
System.out.println("Welcome, " + currentUser.getUsername() + "!");
// Отображение доступных действий
if (currentUser.isAdmin()) {
showAdminActions();
} else {
showUserActions();
}
// Выбор действия
Scanner scanner = new Scanner(System.in);
int choice = scanner.nextInt();
scanner.nextLine(); // Очистка буфера
// Обработка выбранного действия
switch (choice) {
case 1:
displayAllPlants();
break;
case 2:
displayPlantsBySoilType();
break;
case 3:
displayPlantDetails();
break;
case 4:
if (currentUser.isAdmin()) {
addPlant();
} else {
System.out.println("Invalid choice.");
}
break;
case 5:
if (currentUser.isAdmin()) {
removePlant();
} else {
System.out.println("Invalid choice.");
}
break;
default:
System.out.println("Invalid choice.");
break;
}
}
// Метод для входа в систему
private static User login() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter username: ");
String username = scanner.nextLine();
System.out.print("Enter password: ");
String password = scanner.nextLine();
for (User user : users) {
if (user.getUsername().equalsIgnoreCase(username) && user.getPassword().equals(password)) {
return user;
}
}
return null;
}
// Метод для отображения доступных действий для администратора
private static void showAdminActions() {
System.out.println("Select an action:");
System.out.println("1. Display all plants");
System.out.println("2. Display plants by soil type");
System.out.println("3. Display plant details");
System.out.println("4. Add plant");
System.out.println("5. Remove plant");
System.out.print("Your choice: ");
}
// Метод для отображения доступных действий для пользователя
private static void showUserActions() {
System.out.println("Select an action:");
System.out.println("1. Display all plants");
System.out.println("2. Display plants by soil type");
System.out.println("3. Display plant details");
System.out.print("Your choice: ");
}
// Метод для отображения всех растений в оранжерее
private static void displayAllPlants() {
List<Plant> plants = greenhouse.getAllPlants();
System.out.println("All plants in the greenhouse:");
for (Plant plant : plants) {
System.out.println("- " + plant.getName());
}
}
// Метод для отображения растений в оранжерее по типу почвы
private static void displayPlantsBySoilType() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter soil type: ");
String soilType = scanner.nextLine();
List<Plant> plants = greenhouse.getPlantsBySoilType(soilType);
if (plants.isEmpty()) {
System.out.println("No plants found with soil type " + soilType);
} else {
System.out.println("Plants in the greenhouse with soil type " + soilType + ":");
for (Plant plant : plants) {
System.out.println("- " + plant.getName());
}
}
}
// Метод для отображения подробной информации о растении
private static void displayPlantDetails() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter plant name: ");
String plantName = scanner.nextLine();
Plant plant = greenhouse.getPlantByName(plantName);
if (plant == null) {
System.out.println("No plant found with name " + plantName);
} else {
System.out.println("Details of plant " + plantName + ":");
System.out.println("- Soil type: " + plant.getSoil());
System.out.println("- Origin: " + plant.getOrigin());
System.out.println("- Visual parameters:");
Map<String, String> visualParameters = plant.getVisualParameters();
for (String parameter : visualParameters.keySet()) {
System.out.println(" * " + parameter + ": " + visualParameters.get(parameter));
}
System.out.println("- Growing tips:");
Map<String, String> growingTips = plant.getGrowingTips();
for (String tip : growingTips.keySet()) {
System.out.println(" * " + tip + ": " + growingTips.get(tip));
}
System.out.println("- Multiplying method: " + plant.getMultiplying());
}
}
// Метод для добавления растения в оранжерею (доступно только администратору)
private static void addPlant() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter plant name: ");
String name = scanner.nextLine();
System.out.print("Enter soil type: ");
String soil = scanner.nextLine();
System.out.print("Enter origin: ");
String origin = scanner.nextLine();
Map<String, String> visualParameters = new HashMap<>();
System.out.print("Enter stem color: ");
visualParameters.put("stemColor", scanner.nextLine());
System.out.print("Enter leaf color: ");
visualParameters.put("leafColor", scanner.nextLine());
System.out.print("Enter size: ");
visualParameters.put("size", scanner.nextLine());
Map<String, String> growingTips = new HashMap<>();
System.out.print("Enter preferred temperature: ");
growingTips.put("temperature", scanner.nextLine());
System.out.print("Is the plant light-tolerant (yes/no)? ");
String light = scanner.nextLine();
growingTips.put("light", light.equalsIgnoreCase("yes") ? "tolerant" : "non-tolerant");
System.out.print("Enter preferred watering (ml per week): ");
growingTips.put("watering", scanner.nextLine());
System.out.print("Enter multiplying method (seeds/cuttings/leaves): ");
String multiplying = scanner.nextLine();
Plant plant = new Plant(name, soil, origin, visualParameters, growingTips, multiplying);
greenhouse.addPlant(plant);
}
// Метод для удаления растения из оранжереи (доступно только администратору)
private static void removePlant() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter plant name: ");
String plantName = scanner.nextLine();
Plant plant = greenhouse.getPlantByName(plantName);
if (plant == null) {
System.out.println("No plant found with name " + plantName);
} else {
greenhouse.removePlant(plant);
}
}
} |