-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMain.java
More file actions
861 lines (767 loc) · 31.5 KB
/
Copy pathMain.java
File metadata and controls
861 lines (767 loc) · 31.5 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
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
import client.Reservation;
import client.User;
import club.Equipment;
import club.Game_Console;
import club.Game_Field;
import club.Game_Table;
import club.enums.*;
import custom_exceptions.*;
import utility.Database;
import java.util.*;
public class Main {
private static void show_menu() {
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.println("| Sports club management |");
System.out.println("| |");
System.out.println("| 1.Make a reservation |");
System.out.println("| 2.Add a new equipment |");
System.out.println("| 3.Add a new client |");
System.out.println("| 4.Show all equipments |");
System.out.println("| 5.Show all reservations|");
System.out.println("| 6.Show all clients |");
System.out.println("| 7.Manage reservations |");
System.out.println("| 8.Manage clients |");
System.out.println("| 9.Exit |");
System.out.println("| |");
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.print("\n>");
}
private static void show_equipments_menu() {
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.println("| Add a new equipment |");
System.out.println("| |");
System.out.println("| 1.Game field |");
System.out.println("| 2.Game table |");
System.out.println("| 3.Game console |");
System.out.println("| 4.Other equipments |");
System.out.println("| 5.Return |");
System.out.println("| |");
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.print("\n>");
}
private static void show_game_field_types() {
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.println("| Choose a type |");
System.out.println("| |");
System.out.println("| 1.FOOTBALL |");
System.out.println("| 2.FUTSAL |");
System.out.println("| 3.VOLLEYBALL |");
System.out.println("| 4.HANDBALL |");
System.out.println("| 5.TENNIS |");
System.out.println("| 6.HOCKEY |");
System.out.println("| 7.BASKETBALL |");
System.out.println("| 8.BASEBALL |");
System.out.println("| 9.SOCCER |");
System.out.println("| |");
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.print("\n>");
}
private static void show_game_field_classes() {
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.println("| Choose a class |");
System.out.println("| |");
System.out.println("| 1.A |");
System.out.println("| 2.B |");
System.out.println("| 3.C |");
System.out.println("| 4.D |");
System.out.println("| |");
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.print("\n>");
}
private static void show_game_table_types() {
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.println("| Choose a type |");
System.out.println("| |");
System.out.println("| 1.FOOSBALL |");
System.out.println("| 2.PINGPONG |");
System.out.println("| 3.SNOOKER |");
System.out.println("| 4.POOL |");
System.out.println("| |");
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.print("\n>");
}
private static void show_game_table_classes() {
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.println("| Choose a class |");
System.out.println("| |");
System.out.println("| 1.A |");
System.out.println("| 2.B |");
System.out.println("| 3.C |");
System.out.println("| |");
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.print("\n>");
}
private static void show_game_console_types() {
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.println("| Choose a type |");
System.out.println("| |");
System.out.println("| 1.PS3 |");
System.out.println("| 2.PS4 |");
System.out.println("| 3.PS5 |");
System.out.println("| 4.XBOX_ONE |");
System.out.println("| 5.XBOX_ONE_S |");
System.out.println("| 6.XBOX_ONE_X |");
System.out.println("| |");
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.print("\n>");
}
private static void show_reservation_edit_options() {
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.println("| Choose an option |");
System.out.println("| |");
System.out.println("| 1.Change reservation |");
System.out.println("| 2.Pay reservation |");
System.out.println("| 3.Return |");
System.out.println("| |");
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.print("\n>");
}
private static void show_user_edit_options() {
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.println("| Choose an option |");
System.out.println("| |");
System.out.println("| 1.Pay debt |");
System.out.println("| 2.Return |");
System.out.println("| |");
System.out.println("#~~~~~~~~~~~~~~~~~~~~~~~~#");
System.out.print("\n>");
}
private static void clear_screen() {
System.out.print("\033[H\033[2J");
}
private static void show_message(String message) {
Scanner scanner = new Scanner(System.in);
System.out.println(message);
scanner.nextLine();
}
private static void make_reservation() {
Scanner scan = new Scanner(System.in);
String reply;
clear_screen();
System.out.println("Enter a unique id for reservation (Enter nothing to generate a unique id):");
System.out.print(">");
boolean id_empty;
String id = scan.nextLine();
clear_screen();
if (id.contains(" ")) {
show_message("Reservation id must not contain space character.\nAborted!");
return;
}
id_empty = id.isEmpty();
System.out.println("Enter the user id of client:");
System.out.print(">");
String userId = scan.nextLine().trim();
User user;
try {
user = Database.get_user_by_id(userId);
} catch (UserIdNotFoundException e) {
show_message("This user does not exist.\nAborted!");
return;
}
clear_screen();
System.out.println("Enter the equipment code:");
System.out.print(">");
String equipmentCode = scan.nextLine().trim();
Equipment equipment;
try {
equipment = Database.get_equipment_by_code(equipmentCode);
} catch (EquipmentCodeNotFoundException e) {
show_message("This equipment does not exist.\nAborted!");
return;
}
clear_screen();
Date reservation_date;
if (equipment instanceof Game_Field) {
System.out.println("Enter the reservation date:");
int year, month, day, hour, minute;
try {
System.out.print("Year>");
year = Integer.parseInt(scan.nextLine());
if (year < 0)
throw new Exception();
System.out.print("Month>");
month = Integer.parseInt(scan.nextLine());
if (month < 1 || month > 12)
throw new Exception();
System.out.print("Day>");
day = Integer.parseInt(scan.nextLine());
if (day < 1 || day > 31)
throw new Exception();
System.out.print("Hour>");
hour = Integer.parseInt(scan.nextLine());
if (hour < 0 || hour > 23)
throw new Exception();
System.out.print("Minute>");
minute = Integer.parseInt(scan.nextLine());
if (minute < 0 || minute > 59)
throw new Exception();
GregorianCalendar g = new GregorianCalendar(year, month-1, day, hour, minute);
reservation_date = g.getTime();
} catch (Exception e) {
show_message("Invalid input!\nAborted!");
return;
}
} else {
reservation_date = new Date();
}
clear_screen();
Date duration;
System.out.println("Enter the duration of reservation (max: 5h 59m):");
int hour, minute;
try {
System.out.print("Hour>");
hour = Integer.parseInt(scan.nextLine());
if (hour < 0 || hour > 5)
throw new Exception();
System.out.print("Minute>");
minute = Integer.parseInt(scan.nextLine());
if (minute < 0 || minute > 59)
throw new Exception();
GregorianCalendar g = new GregorianCalendar(0, 0, 0, hour, minute);
duration = g.getTime();
} catch (Exception e) {
show_message("Invalid input!\nAborted!");
return;
}
GregorianCalendar g = new GregorianCalendar();
g.setTime(duration);
clear_screen();
System.out.printf("Reservation id: %s\nReservation user: %s\nReservation equipment: %s\nReservation reserve date: %s\nReservation duration: %d:%d\n\n", id, user.getId(), equipment.getCode(), reservation_date, g.get(Calendar.HOUR), g.get(Calendar.MINUTE));
System.out.println("Are you sure? [Y/n]");
System.out.print(">");
reply = scan.nextLine();
if (reply.trim().equalsIgnoreCase("n")){
clear_screen();
show_message("Aborted!");
return;
}
clear_screen();
Reservation reservation;
try {
if (id_empty)
reservation = new Reservation(user, equipment, reservation_date, duration);
else
reservation = new Reservation(id, user, equipment, reservation_date, duration);
} catch (ReservationDatePassedException | DurationLimitException e) {
show_message("Reservation date has passed\nAborted!");
return;
}
Database.insert_reservation(reservation);
System.out.println("Reservation has been successfully added to database.");
scan.nextLine();
}
private static void add_equipment() {
Scanner scan = new Scanner(System.in);
String reply;
while (true) {
clear_screen();
show_equipments_menu();
String menu_reply = scan.nextLine();
if (menu_reply.equals("5"))
return;
if (menu_reply.equals("4")) {
clear_screen();
System.out.println("Enter a unique code for equipment (Enter nothing to generate a unique code): ");
System.out.print(">");
boolean id_empty;
String id = scan.nextLine();
clear_screen();
if (id.contains(" ")) {
show_message("Equipment code must not contain space character.\nAborted!");
return;
}
id_empty = id.isEmpty();
System.out.println("Enter a price for using the equipment:");
System.out.print(">");
long price;
try {
price = Long.parseLong(scan.nextLine());
} catch (NumberFormatException e) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
clear_screen();
System.out.printf("Equipment code: %s\nEquipment price: %d\n\n", id, price);
System.out.println("Are you sure? [Y/n]");
System.out.print(">");
reply = scan.nextLine();
if (reply.trim().equalsIgnoreCase("n")){
clear_screen();
show_message("Aborted!");
return;
}
Equipment equipment;
if (id_empty)
equipment = new Equipment(price);
else
equipment = new Equipment(id, price);
Database.insert_equipment(equipment);
clear_screen();
System.out.println("Equipment has been successfully added to database.");
scan.nextLine();
return;
}
if (menu_reply.equals("3")) {
clear_screen();
System.out.println("Enter a unique code for game console (Enter nothing to generate a unique code): ");
System.out.print(">");
boolean id_empty;
String id = scan.nextLine();
clear_screen();
if (id.contains(" ")) {
show_message("Game console code must not contain space character.\nAborted!");
return;
}
id_empty = id.isEmpty();
System.out.println("Enter a price for using the game console:");
System.out.print(">");
long price;
try {
price = Long.parseLong(scan.nextLine());
} catch (NumberFormatException e) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
clear_screen();
show_game_console_types();
int ct;
try {
ct = Integer.parseInt(scan.nextLine());
} catch (NumberFormatException e) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
if (ct < 1 || ct > 6) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
Console_Type console_type = Console_Type.values()[ct-1];
boolean vip;
clear_screen();
System.out.println("vip game console? [N/y]");
System.out.print(">");
reply = scan.nextLine();
vip = reply.trim().equalsIgnoreCase("y");
clear_screen();
System.out.printf("Game console code: %s\nGame console price: %d\nGame console type: %s\nvip: %s\n", id, price, console_type, vip);
System.out.println("Are you sure? [Y/n]");
System.out.print(">");
reply = scan.nextLine();
if (reply.trim().equalsIgnoreCase("n")){
clear_screen();
show_message("Aborted!");
return;
}
Game_Console game_console;
if (id_empty)
game_console = new Game_Console(price, console_type, vip);
else
game_console = new Game_Console(id, price, console_type, vip);
Database.insert_equipment(game_console);
clear_screen();
System.out.println("Game console has been successfully added to database.");
scan.nextLine();
return;
}
if (menu_reply.equals("2")) {
clear_screen();
System.out.println("Enter a unique code for game table (Enter nothing to generate a unique code): ");
System.out.print(">");
boolean id_empty;
String id = scan.nextLine();
clear_screen();
if (id.contains(" ")) {
show_message("Game table code must not contain space character.\nAborted!");
return;
}
id_empty = id.isEmpty();
System.out.println("Enter a price for using the game table:");
System.out.print(">");
long price;
try {
price = Long.parseLong(scan.nextLine());
} catch (NumberFormatException e) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
clear_screen();
show_game_table_types();
int tt;
try {
tt = Integer.parseInt(scan.nextLine());
} catch (NumberFormatException e) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
if (tt < 1 || tt > 4) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
Table_Type table_type = Table_Type.values()[tt-1];
clear_screen();
show_game_table_classes();
int tc;
try {
tc = Integer.parseInt(scan.nextLine());
} catch (NumberFormatException e) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
if (tc < 1 || tc > 3) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
Table_Class table_class = Table_Class.values()[tc-1];
clear_screen();
System.out.printf("Game table code: %s\nGame table price: %d\nGame table type: %s\nGame table class: %s\n", id, price, table_type, table_class);
System.out.println("Are you sure? [Y/n]");
System.out.print(">");
reply = scan.nextLine();
if (reply.trim().equalsIgnoreCase("n")){
clear_screen();
show_message("Aborted!");
return;
}
Game_Table game_table;
if (id_empty)
game_table = new Game_Table(price, table_type, table_class);
else
game_table = new Game_Table(id, price, table_type, table_class);
Database.insert_equipment(game_table);
clear_screen();
System.out.println("Game table has been successfully added to database.");
scan.nextLine();
return;
}
if (menu_reply.equals("1")) {
clear_screen();
System.out.println("Enter a unique code for game field (Enter nothing to generate a unique code): ");
System.out.print(">");
boolean id_empty;
String id = scan.nextLine();
clear_screen();
if (id.contains(" ")) {
show_message("Game field code must not contain space character.\nAborted!");
return;
}
id_empty = id.isEmpty();
System.out.println("Enter a price for using the game field:");
System.out.print(">");
long price;
try {
price = Long.parseLong(scan.nextLine());
} catch (NumberFormatException e) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
if (price < 0) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
clear_screen();
System.out.println("Enter limit for capacity of game field:");
System.out.print(">");
int capacity;
try {
capacity = Integer.parseInt(scan.nextLine());
} catch (NumberFormatException e) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
if (capacity < 0) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
clear_screen();
show_game_field_types();
int ft;
try {
ft = Integer.parseInt(scan.nextLine());
} catch (NumberFormatException e) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
if (ft < 1 || ft > 9) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
Field_Type field_type = Field_Type.values()[ft-1];
clear_screen();
show_game_field_classes();
int fc;
try {
fc = Integer.parseInt(scan.nextLine());
} catch (NumberFormatException e) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
if (fc < 1 || fc > 4) {
clear_screen();
show_message("Invalid input!\nAborted!");
return;
}
Field_Class field_class = Field_Class.values()[fc-1];
clear_screen();
System.out.printf("Game field code: %s\nGame field price: %d\nGame field capacity: %d\nGame field type: %s\nGame field class: %s\n", id, price, capacity, field_type, field_class);
System.out.println("Are you sure? [Y/n]");
System.out.print(">");
reply = scan.nextLine();
if (reply.trim().equalsIgnoreCase("n")){
clear_screen();
show_message("Aborted!");
return;
}
Game_Field game_field;
if (id_empty)
game_field = new Game_Field(price, capacity, field_type, field_class);
else
game_field = new Game_Field(id, price, capacity, field_type, field_class);
Database.insert_equipment(game_field);
clear_screen();
System.out.println("Game field has been successfully added to database.");
scan.nextLine();
return;
}
}
}
private static void add_client() {
Scanner scan = new Scanner(System.in);
String reply;
clear_screen();
System.out.println("Enter a unique id for client (Enter nothing to generate a unique code): ");
System.out.print(">");
boolean id_empty;
String id = scan.nextLine();
clear_screen();
if (id.contains(" ")) {
show_message("client id must not contain space character.\nAborted!");
return;
}
id_empty = id.isEmpty();
System.out.println("Enter a name for client:");
System.out.print(">");
String name = scan.nextLine();
clear_screen();
if (name.trim().isEmpty()) {
show_message("Name must be at least one character.\nAborted!");
return;
}
System.out.printf("User id: %s\nUser name: %s\n\n", id, name);
System.out.println("Are you sure? [Y/n]");
System.out.print(">");
reply = scan.nextLine();
if (reply.trim().equalsIgnoreCase("n")){
clear_screen();
show_message("Aborted!");
return;
}
User user;
if (id_empty)
user = new User(name);
else
user = new User(id, name);
Database.insert_user(user);
clear_screen();
System.out.println("User has been successfully added to database.");
scan.nextLine();
}
private static void show_all_equipments() {
clear_screen();
System.out.println();
List<Equipment> list = Database.getEquipment_list();
for (Equipment equipment: list) {
System.out.println(equipment);
}
System.out.println();
}
private static void show_all_reservations() {
clear_screen();
System.out.println();
List<Reservation> list = Database.getReservation_list();
for (Reservation reservation: list) {
System.out.println(reservation);
}
System.out.println();
}
private static void show_all_clients() {
clear_screen();
System.out.println();
List<User> list = Database.getUser_list();
for (User user: list) {
System.out.println(user);
}
System.out.println();
}
private static void edit_reservations() {
Scanner scan = new Scanner(System.in);
String reply;
clear_screen();
System.out.println("Enter the id of reservation you want to edit:");
System.out.print(">");
String reservationId = scan.nextLine().trim();
Reservation reservation;
try {
reservation = Database.get_reservation_by_id(reservationId);
} catch (ReservationIdNotFoundException e) {
show_message("This reservation does not exist.\nAborted!");
return;
}
while (true) {
clear_screen();
System.out.println(reservation);
System.out.println();
show_reservation_edit_options();
String menu_reply = scan.nextLine();
if (menu_reply.equals("1")) {
clear_screen();
Date reservation_date;
System.out.println("Enter the reservation date:");
int year, month, day, hour, minute;
try {
System.out.print("Year>");
year = Integer.parseInt(scan.nextLine());
if (year < 0)
throw new Exception();
System.out.print("Month>");
month = Integer.parseInt(scan.nextLine());
if (month < 1 || month > 12)
throw new Exception();
System.out.print("Day>");
day = Integer.parseInt(scan.nextLine());
if (day < 1 || day > 31)
throw new Exception();
System.out.print("Hour>");
hour = Integer.parseInt(scan.nextLine());
if (hour < 0 || hour > 23)
throw new Exception();
System.out.print("Minute>");
minute = Integer.parseInt(scan.nextLine());
if (minute < 0 || minute > 59)
throw new Exception();
GregorianCalendar g = new GregorianCalendar(year, month-1, day, hour, minute);
reservation_date = g.getTime();
} catch (Exception e) {
show_message("Invalid input!\nAborted!");
return;
}
Database.change_reservation_reserve_date(reservation.getId(), reservation_date);
clear_screen();
show_message("Reservation date has been successfully updated!");
return;
}
if (menu_reply.equals("2")) {
reservation.pay();
clear_screen();
show_message("Reservation is paid. check user's info for final checkout.");
return;
}
if (menu_reply.equals("3"))
return;
}
}
private static void edit_clients() {
Scanner scan = new Scanner(System.in);
String reply;
clear_screen();
System.out.println("Enter the id of user you want to manage:");
System.out.print(">");
String userId = scan.nextLine().trim();
User user;
try {
user = Database.get_user_by_id(userId);
} catch (UserIdNotFoundException e) {
clear_screen();
show_message("This user does not exist.\nAborted!");
return;
}
while (true) {
clear_screen();
System.out.println(user);
System.out.println();
show_user_edit_options();
String menu_reply = scan.nextLine();
if (menu_reply.equals("1")) {
clear_screen();
long debt;
System.out.println("How much do you want to pay? :");
System.out.print(">");
try {
debt = Long.parseLong(scan.nextLine());
if (debt < 0)
throw new Exception();
if (debt > user.getDebt()) {
clear_screen();
show_message("This cash is more than client's debt!\nAborted!");
return;
}
} catch (Exception e) {
show_message("Invalid input!\nAborted!");
return;
}
user.pay_debt(debt);
clear_screen();
show_message("Paid successfully!");
return;
}
if (menu_reply.equals("2"))
return;
}
}
public static void main(String[] args) {
clear_screen();
Scanner scan = new Scanner(System.in);
label:
while (true) {
show_menu();
String menu_reply = scan.nextLine();
switch (menu_reply) {
case "1":
make_reservation();
break;
case "2":
add_equipment();
break;
case "3":
add_client();
break;
case "4":
show_all_equipments();
scan.nextLine();
break;
case "5":
show_all_reservations();
scan.nextLine();
break;
case "6":
show_all_clients();
scan.nextLine();
break;
case "7":
edit_reservations();
break;
case "8":
edit_clients();
break;
case "9":
break label;
}
clear_screen();
}
}
}