-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestHomeless.java
1565 lines (1409 loc) · 60 KB
/
TestHomeless.java
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
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
SECJ2154 - 07 OBJECT-ORIENTED PROGRAMMING
HOMELESS SHELTER MANAGEMENT SYSTEM [GROUP KeJumpz]
==================================================
This program is a simple system that allows the user to manage a shelter.
LECTURER: DR. NORSHYAM BINTI IDRIS 7321
TEAM MEMBER LIST:
[1] AUM JEEVAN A/L NIRANGKAR A20EC0017
[2] BRENDAN DYLAN GAMPA ANAK JOSEPH DUSIT A20EC0021
[3] IESKANDAR ZULQARNAIN BIN GHAZALI A20EC0046
[4] MOHAMAD HAZIQ ZIKRY BIN MOHAMMAD RAZAK A20EC0079
CLASS NAME : TestHomeless
DESCRIPTION : This class is used to test the functionality of the program.
AUTHOR : ALL TEAM MEMBER
*/
import java.util.*;
import java.io.*;
import java.time.*;
public class TestHomeless {
LocalDate date = LocalDate.now();
static ArrayList<Admin> admin = new ArrayList<Admin>();
static ArrayList<Volunteer> volunteer = new ArrayList<Volunteer>();
static ArrayList<BasicNeeds> bNeeds = new ArrayList<BasicNeeds>();
static ArrayList<AdultLess> adult = new ArrayList<AdultLess>();
static ArrayList<ChildLess> child = new ArrayList<ChildLess>();
static ArrayList<Shelter> shelter = new ArrayList<Shelter>();
static int ad = 0;
static int vol = 0;
static int bn = 0;
static Scanner sc = new Scanner(System.in);
static Scanner in1 = new Scanner(System.in);
static Scanner in2 = new Scanner(System.in);
static int choiceA; // choice adult CASE 2 volunteer menu
static int choiceA2; // choice adult CASE 2 volunteer menu
static int choiceC; // choice child CASE 2 volunteer menu
static int choiceC2; // choice child CASE 2 volunteer menu
static int choose = 0; // general selection for services
static int chooseBneed; // general selection for basic needs
static int choiceB; // choice basic needs CASE 2 volunteer menu
static char category; // choose category of homeless people
static boolean opstatus; // orphan status
static boolean adminOpt; // admin option
public static void main(String[] args) throws Exception {
readFile();
boolean test = false;
Login l = new Login();
Registration Reg = new Registration();
do {
Clrscr();
System.out.println("<< HELLO AND WELCOME TO HOMELESS SHELTER MANAGEMENT SYSTEM >>");
printLine();
System.out.println("1 - Login");
System.out.println("2 - Register New User");
System.out.println("0 - Terminated");
printLine();
System.out.println();
System.out.print("Option :: ");
choose = sc.nextInt();
switch (choose) {
// login
case 1:
Clrscr();
l.WelcomeMessage();
l.readUserInput(admin, volunteer);
// user type home page
if (l.getUserType() == 'A') {
do {
Clrscr();
adminOpt = false;
System.out.println("<<< SERVICES AVAILABLE >>>");
printLine();
System.out.println("[1] Manage Shelter");
System.out.println("[2] Manage Volunteer");
System.out.println("[3] Manage Basic Needs");
System.out.println("[4] Logout");
printLine();
System.out.print("Option :: ");
choose = sc.nextInt();
switch (choose) {
// manage shelter
case 1:
ManageShelter();
adminOpt = true;
break;
// manage volunteer
case 2:
if (volunteer.size() == 0) {
System.out.println();
System.out.println("No volunteer registered");
} else {
manageVolunteer();
}
adminOpt = true;
break;
// manage basic needs
case 3:
managebasicneed();
adminOpt = true;
break;
// logout
case 4:
System.out.println("Returning back to main Page!");
adminOpt = false;
break;
default:
System.out.println("Invalid Choice! Please Select Again!");
adminOpt = true;
break;
}
SystemPause();
} while (adminOpt);
} else if (l.getUserType() == 'V') {
do {
Clrscr();
System.out.println("<<< SERVICES AVAILABLE >>>");
printLine();
System.out.println("[1] Add Homeless People");
System.out.println("[2] Update Homeless People");
System.out.println("[3] Delete Homeless People");
System.out.println("[4] Display Homeless People List");
System.out.println("[5] Logout");
printLine();
System.out.print("Option :: ");
choose = sc.nextInt();
switch (choose) {
case 1:
// add homeless people
Clrscr();
addHomeless();
SystemPause();
break;
case 2:
// update homeless people
Clrscr();
updateHomeless();
SystemPause();
break;
case 3:
// delete homeless people
Clrscr();
deleteHomeless();
SystemPause();
break;
case 4:
// display homeless people list
Clrscr();
displayHomelessPeople();
SystemPause();
break;
case 5:
System.out.println();
System.out.println("You are logging out");
break;
default:
System.out.println("Sorry! The services selected is not available!");
break;
}
} while (choose >= 1 && choose <= 4);
}
test = true;
break;
case 2:
// registration
Clrscr();
Reg.WelcomeMessage();
registerNewUser();
test = true;
break;
case 0:
// exit system
System.out.println();
System.out.println("Thank you for using our system");
test = false;
break;
default:
System.out.println();
System.out.println("INVALID CHOICE!");
test = true;
break;
}
SystemPause();
} while (test);
sc.close();
in1.close();
in2.close();
}
/*
* FUNCTION NAME : registerNewUser
* DESCRIPTION : this function is used to register new admin or volunteer
* AUTHOR : Brendan Dylan Gampa anak Joseph Dusit@Dusit A20EC0021
*/
public static void registerNewUser() throws Exception {
String username, password, fname, lname, gender;
int age;
char userType;
Shelter workloca;
int choose = 0;
boolean test = false;
do {
test = false;
System.out.print("Select user type: ");
userType = in1.next().charAt(0);
in1.nextLine();
if (Character.toUpperCase(userType) != 'A' && Character.toUpperCase(userType) != 'V') {
System.out.println("The entered user type is not available. Please input again.");
System.out.println();
test = true;
}
} while (test);
System.out.println();
System.out.print("Username :: ");
username = in1.nextLine();
System.out.print("Password :: ");
password = in2.nextLine();
System.out.print("First name :: ");
fname = in1.nextLine();
System.out.print("Last name :: ");
lname = in2.nextLine();
System.out.print("Gender :: ");
gender = in1.nextLine();
System.out.print("Age :: ");
age = in1.nextInt();
if (Character.toUpperCase(userType) == 'V') {
System.out.println();
TestHomeless.displayLocation();
do {
System.out.print("Option :: ");
choose = sc.nextInt();
} while (choose < 1 || choose > shelter.size());
workloca = shelter.get(choose - 1);
// send to volunteer class
volunteer.add(new Volunteer(fname, lname, gender, age, username, password, workloca));
} else if (Character.toUpperCase(userType) == 'A') {
// send to admin class
admin.add(new Admin(fname, lname, gender, age, username, password));
}
// update file
saveFile();
}
/*
* FUNCTION NAME : reducebasicneeds
* DESCRIPTION : function for reduce basic needs upon sign up
* AUTHOR : AUM JEEVAN A/L JEEVAN A20EC0021
*/
static void reducebasicneeds() {
for (int i = 0; i < bNeeds.size(); i++) {
bNeeds.get(i).decrementQuantity();
System.out.println("You are eligible for 1 " + bNeeds.get(i).getBasicName() + ".");
}
}
/*
* FUNCTION NAME : managebasicneed
* DESCRIPTION : function for managing basic needs
* AUTHOR : AUM JEEVAN A/L JEEVAN A20EC0021
*/
static void managebasicneed() throws Exception {
boolean test;
do {
Clrscr();
test = false;
System.out.println("<<< SERVICES AVAILABLE >>>");
printLine();
System.out.println("[1] Check Balance");
System.out.println("[2] Update Quantity");
System.out.println("[3] Add Basic Needs");
System.out.println("[4] Delete Basic Needs");
System.out.println("[0] Go back to Admin Page");
printLine();
System.out.print("Option :: ");
chooseBneed = sc.nextInt();
switch (chooseBneed) {
case 1:
balanceChecking();
break;
case 2:
updateQuantity();
break;
case 3:
Clrscr();
addBasicNeeds();
break;
case 4:
deleteBasicNeeds();
break;
case 0:
System.out.println();
System.out.println("Go back to Admin Page!");
test = false;
break;
default:
System.out.println();
System.out.println("Invalid Choice! Please Select Again!");
test = true;
break;
}
} while (test);
}
/*
* FUNCTION NAME : displayBasicNeeds
* DESCRIPTION : function to display basic needs
* AUTHOR : AUM JEEVAN A/L JEEVAN A20EC0021
*/
static void displayBasicNeeds() {
printLine();
System.out.println("<<< LIST OF BASIC NEEDS >>>");
printLine();
String str = "";
System.out.printf("%-4s %-15s %-10s %-6s", "No",
"Name", "Quantity", "Description",
"Type");
System.out.println();
for (int i = 0; i < bNeeds.size(); i++) {
str = "[" + (i + 1) + "] ";
System.out.printf("%-1s %-15s %-10s %-6s", str,
bNeeds.get(i).getBasicName(), bNeeds.get(i).getQuantity(),
bNeeds.get(i).getDesc(), bNeeds.get(i).getType());
System.out.println();
}
printLine();
}
/*
* FUNCTION NAME : balanceChecking
* DESCRIPTION : function to check balance of the basic needs
* AUTHOR : AUM JEEVAN A/L JEEVAN A20EC0021
*/
static void balanceChecking() {
boolean test;
do {
test = false;
Clrscr();
if (bNeeds.size() == 0) {
System.out.println("No basic needs in the list!");
return;
}
displayBasicNeeds();
System.out.println();
System.out.print("Choose Basic Need To View: ");
choiceB = in1.nextInt();
if (choiceB < 1 || choiceB > bNeeds.size()) {
test = true;
System.out.println("Invalid Selection! Please Select again");
}
} while (test);
bNeeds.get(choiceB - 1).balancecheck();
}
/*
* FUNCTION NAME : updateQuantity
* DESCRIPTION : function to update the quantity of the chosen basic needs
* AUTHOR : AUM JEEVAN A/L JEEVAN A20EC0021
*/
static void updateQuantity() throws Exception {
boolean test;
do {
test = false;
Clrscr();
displayBasicNeeds();
System.out.println();
System.out.print("Choose Basic Need To Update: ");
choiceB = in1.nextInt();
printLine();
if (choiceB < 1 || choiceB > bNeeds.size()) {
test = true;
System.out.println("Invalid Selection! Please Select again");
}
} while (test);
System.out.print("Enter New Quantity: ");
int tempNewQuantity = in1.nextInt();
bNeeds.get(choiceB - 1).setQuantity(tempNewQuantity);
// update file
saveFile();
}
/*
* FUNCTION NAME : deleteBasicNeeds
* DESCRIPTION : function to delete basic needs
* AUTHOR : AUM JEEVAN A/L JEEVAN A20EC0021
*/
static void deleteBasicNeeds() throws Exception {
boolean test;
int index;
do {
test = false;
Clrscr();
displayBasicNeeds();
System.out.println();
System.out.print("Enter the index of the basic needs you want to delete: ");
index = sc.nextInt();
if (index < 1 || index > bNeeds.size()) {
test = true;
System.out.println("Invalid Selection! Please Select again");
}
} while (test);
bNeeds.remove(index - 1);
System.out.println("You have deleted the basic needs");
saveFile();
}
/*
* FUNCTION NAME : addBasicNeeds
* DESCRIPTION : function to add basic needs
* AUTHOR : AUM JEEVAN A/L JEEVAN A20EC0021
*/
static void addBasicNeeds() throws Exception {
Scanner input = new Scanner(System.in);
String basicName, Desc;
int quantity;
char type;
printLine();
System.out.println("<<< ADDING NEW BASIC NEEDS >>>");
printLine();
System.out.print(" Enter the name :: ");
basicName = input.nextLine();
System.out.print(" Enter the quantity :: ");
quantity = sc.nextInt();
System.out.print(" Enter the descriptions :: ");
Desc = input.nextLine();
System.out.print("Enter the type [m-meal, c-clothes, h-healthcare] :: ");
type = sc.next().charAt(0);
bNeeds.add(new BasicNeeds(basicName, quantity, Desc, type));
System.out.println();
System.out.println(" You have added the basic needs!");
// update file
saveFile();
}
/*
* FUNCTION NAME : displayLocation
* DESCRIPTION : function to display location of shelters
* AUTHOR : MOHAMAD HAZIQ ZIKRY BIN MOHAMMAD RAZAK A20EC0079
*/
static void displayLocation() {
System.out.println("<<< " + shelter.size() + " LOCATIONS TO CHOOSE >>>");
printLine();
for (int i = 0; i < shelter.size(); i++) {
System.out.println("[" + (i + 1) + "] " + shelter.get(i).getshelName() + ", " + shelter.get(i).getCity()
+ ", " + shelter.get(i).getState());
}
printLine();
}
/*
* FUNCTION NAME : displayVolunteer
* DESCRIPTION : function to display volunteer list
* AUTHOR : MOHAMAD HAZIQ ZIKRY BIN MOHAMMAD RAZAK A20EC0079
*/
static void displayVolunteer() {
System.out.println("<<< LIST OF VOLUNTEER TO CHOOSE >>>");
printLine();
String str = "";
System.out.printf("%-5s %-30s %-20s %n", "No", "Name", "Volunteer ID");
for (int i = 0; i < volunteer.size(); i++) {
str = "[" + (i + 1) + "] ";
System.out.printf("%-5s %-30s %-20s %n", str, volunteer.get(i).getName(),
volunteer.get(i).getVolunteerID());
}
printLine();
}
/*
* FUNCTION NAME : addHomeless
* DESCRIPTION : add homeless people into the list of homeless adult and
* children
* AUTHOR : Brendan Dylan Gampa anak Joseph Dusit@Dusit A20EC0021
*/
static void addHomeless() throws Exception {
Scanner a1 = new Scanner(System.in);
Scanner a2 = new Scanner(System.in);
Scanner a3 = new Scanner(System.in);
Scanner a4 = new Scanner(System.in);
Scanner c1 = new Scanner(System.in);
Scanner c2 = new Scanner(System.in);
// input
String firstName, lastName, gender, cid, aid, pname, pocc;
int age, stayDays;
Shelter location;
System.out.println("<<< ADD HOMELESS PEOPLE >>>");
printLine();
System.out.print("First Name: ");
firstName = a1.nextLine();
System.out.print("Last Name: ");
lastName = a2.nextLine();
System.out.print("Gender: ");
gender = a1.nextLine();
System.out.print("Age: ");
age = a1.nextInt();
System.out.println();
displayLocation();
do {
System.out.print("Option :: ");
choose = sc.nextInt();
} while (choose < 1 || choose > shelter.size());
location = shelter.get(choose - 1);
System.out.print("Days staying: ");
stayDays = in1.nextInt();
sc.nextLine();
// validate age
if (age > 0 && age <= 15) {
System.out.print("Child ID: ");
cid = c1.next();
System.out.print("Parent name (Type - if none): ");
pname = c2.next();
if (pname.equals("-")) {
pname = "None";
opstatus = true;
} else {
opstatus = false;
}
// send to ChildLess class
child.add(new ChildLess(firstName, lastName, gender, age, location, stayDays, cid, pname, opstatus));
// save input into text file
saveFile();
} else if (age > 15 && age < 90) {
System.out.print("Adult ID: ");
aid = a3.nextLine();
System.out.print("Past Occupation: ");
pocc = a4.nextLine();
// send to Adultless class
adult.add(new AdultLess(firstName, lastName, gender, age, location, stayDays, aid, pocc));
// save input into text file
saveFile();
} else {
System.out.println("Invalid age.");
}
// invoke reduce basic needs function
reducebasicneeds();
//clear buffer
in1.nextLine();
in2.nextLine();
a1.nextLine();
a2.nextLine();
a3.nextLine();
a4.nextLine();
c1.nextLine();
c2.nextLine();
System.out.println();
}
/*
* FUNCTION NAME : updateHomeless
* DESCRIPTION : function to update homeless people
* AUTHOR : Brendan Dylan Gampa anak Joseph Dusit@Dusit A20EC0021
*/
static void updateHomeless() throws Exception {
Scanner a1 = new Scanner(System.in);
Scanner a2 = new Scanner(System.in);
String tempfirstName, templastName, tempgender, temppname, inputorphan;
int tempage, tempstayDays;
String tempaid, tempchildID, temppastOccupation;
boolean temporphan = false;
Shelter templocation;
System.out.println("<<< UPDATE HOMELESS PEOPLE >>>");
printLine();
System.out.println("Please select which category you want to update");
printLine();
System.out.println("ADULT - A");
System.out.println("CHILD - C");
printLine();
System.out.print("Option :: ");
category = in1.next().charAt(0);
in1.nextLine(); // clear buffer
Clrscr();
if (Character.toUpperCase(category) == 'A') {
if (adult.size() == 0) {
System.out.println("No adult list to be deleted");
} else {
int numA = 1;
System.out.printf("%-3s %-15s %-10s %-6s %-40s %-15s %-10s %-15s", "No",
"Full name", "Gender", "Age",
"Location", "Days stayed", "Adult ID", "Past Occupation");
System.out.println();
printLine();
for (int i = 0; i < adult.size(); i++) {
System.out.printf("[%-1s] %-15s %-10s %-6s %-40s %-15s %-10s %-15s",
numA, adult.get(i).getName(), adult.get(i).getGender(),
adult.get(i).getAge(), adult.get(i).getLocation(),
adult.get(i).getStayDays(), adult.get(i).getAdultID(),
adult.get(i).getOccup());
System.out.println();
numA++;
}
printLine();
System.out.println();
System.out.print("Choose Adult To Update: ");
choiceA = in1.nextInt();
printLine();
System.out.println("[1] First Name");
System.out.println("[2] Last Name");
System.out.println("[3] Gender");
System.out.println("[4] Age");
System.out.println("[5] Location");
System.out.println("[6] Stay Days");
System.out.println("[7] Adult ID");
System.out.println("[8] Past Occupation");
System.out.println();
System.out.print("Choose item to update: ");
choiceA2 = in1.nextInt();
printLine();
System.out.println();
if (choiceA2 == 1) {
System.out.print("Enter New First Name: ");
tempfirstName = a1.nextLine();
adult.get(choiceA - 1).setfirstName(tempfirstName);
System.out.println(adult.get(choiceA - 1).getfName() + " has been updated.");
} else if (choiceA2 == 2) {
System.out.print("Enter New Last Name: ");
templastName = a2.nextLine();
adult.get(choiceA - 1).setlastName(templastName);
System.out.println(adult.get(choiceA - 1).getlName() + " has been updated.");
} else if (choiceA2 == 3) {
System.out.print("Enter New Gender: ");
tempgender = a1.next();
adult.get(choiceA - 1).setgender(tempgender);
System.out.println(adult.get(choiceA - 1).getGender() + " has been updated.");
} else if (choiceA2 == 4) {
System.out.print("Enter New Age: ");
tempage = a1.nextInt();
adult.get(choiceA - 1).setAge(tempage);
System.out.println(adult.get(choiceA - 1).getAge() + " has been updated.");
} else if (choiceA2 == 5) {
displayLocation();
do {
System.out.print("Option :: ");
choose = sc.nextInt();
} while (choose < 1 || choose >= shelter.size());
templocation = shelter.get(choose - 1);
adult.get(choiceA - 1).setLocation(templocation);
System.out.println(adult.get(choiceA - 1).getLocation() + " has been updated.");
} else if (choiceA2 == 6) {
System.out.print("Enter New Stay Days: ");
tempstayDays = in1.nextInt();
adult.get(choiceA - 1).setStaydays(tempstayDays);
System.out.println(adult.get(choiceA - 1).getStayDays() + " has been updated.");
} else if (choiceA2 == 7) {
System.out.print("Enter New Adult ID: ");
tempaid = in1.next();
adult.get(choiceA - 1).setaid(tempaid);
System.out.println(adult.get(choiceA - 1).getAdultID() + " has been updated.");
} else if (choiceA2 == 8) {
System.out.print("Enter New Past Occupation: ");
temppastOccupation = in1.next();
adult.get(choiceA - 1).setpocc(temppastOccupation);
System.out.println(adult.get(choiceA - 1).getOccup() + " has been updated.");
} else if (choiceA2 == 9) {
System.out.println("Exiting Update.");
} else {
System.out.println("Invalid Input.");
}
}
} else if (Character.toUpperCase(category) == 'C') {
if (child.size() == 0) {
System.out.println("No child list to be deleted");
} else {
int numC = 1;
String childstatus = " ";
System.out.printf("%-3s %-15s %-10s %-6s %-40s %-15s %-10s %-15s %-20s",
"No", "Full name", "Gender", "Age", "Location", "Days stayed",
"Child ID",
"Parent Name", "Orphan Status");
System.out.println();
printLine();
for (int i = 0; i < child.size(); i++) {
// verify child status
if (child.get(i).getOrphanStatus() == true) {
childstatus = "Orphan";
} else if (child.get(i).getOrphanStatus() == false) {
childstatus = "Non-orphan";
}
System.out.printf(
"[%-1s] %-15s %-10s %-6s %-40s %-15s %-10s %-15s %-20s",
numC, child.get(i).getName(), child.get(i).getGender(),
child.get(i).getAge(), child.get(i).getLocation(),
child.get(i).getStayDays(), child.get(i).getChildID(),
child.get(i).getParentName(), childstatus);
System.out.println();
numC++;
}
printLine();
System.out.println();
System.out.print("Choose Child To Update: ");
choiceC = in1.nextInt();
printLine();
System.out.println();
System.out.println("[1] First Name");
System.out.println("[2] Last Name");
System.out.println("[3] Gender");
System.out.println("[4] Age");
System.out.println("[5] Location");
System.out.println("[6] Stay Days");
System.out.println("[7] Child ID");
System.out.println("[8] Parent Name");
System.out.println("[9] Orphan Status");
System.out.println();
System.out.print("Choose item to update: ");
choiceC2 = in1.nextInt();
printLine();
System.out.println();
// update child
if (choiceC2 == 1) {
System.out.print("Enter New First Name: ");
tempfirstName = in1.next();
child.get(choiceC - 1).setfirstName(tempfirstName);
System.out.println(child.get(choiceC - 1).getfName() + " has been updated.");
} else if (choiceC2 == 2) {
System.out.print("Enter New Last Name: ");
templastName = in1.next();
child.get(choiceC - 1).setlastName(templastName);
System.out.println(child.get(choiceC - 1).getlName() + " has been updated.");
} else if (choiceC2 == 3) {
System.out.print("Enter New Gender: ");
tempgender = in1.next();
child.get(choiceC - 1).setgender(tempgender);
System.out.println(child.get(choiceC - 1).getAge() + "has been updated.");
} else if (choiceC2 == 4) {
System.out.print("Enter New Age: ");
tempage = in1.nextInt();
child.get(choiceC - 1).setAge(tempage);
System.out.println(child.get(choiceC - 1).getAge() + " has been updated.");
} else if (choiceC2 == 5) {
displayLocation();
do {
System.out.print("Option :: ");
choose = sc.nextInt();
} while (choose < 1 || choose >= shelter.size());
templocation = shelter.get(choose - 1);
child.get(choiceC - 1).setLocation(templocation);
System.out.println(child.get(choiceC - 1).getLocation() + " has been updated.");
} else if (choiceC2 == 6) {
System.out.print("Enter New Stay Days: ");
tempstayDays = in1.nextInt();
child.get(choiceC - 1).setStaydays(tempstayDays);
System.out.println(child.get(choiceC - 1).getStayDays() + " has been updated.");
} else if (choiceC2 == 7) {
System.out.print("Enter New Child ID: ");
tempchildID = in1.next();
child.get(choiceC - 1).setChildID(tempchildID);
System.out.println(child.get(choiceC - 1).getChildID() + " has been updated.");
} else if (choiceC2 == 8) {
System.out.print("Enter New Parent Name: ");
temppname = in1.next();
child.get(choiceC - 1).setpname(temppname);
System.out.println(child.get(choiceC - 1).getParentName() + " has been updated.");
} else if (choiceC2 == 9) {
System.out.print("Enter New Orphan Status [YES/NO]: ");
inputorphan = in1.next();
if (inputorphan.equals("YES")) {
temporphan = true;
} else if (inputorphan.equals("NO")) {
temporphan = false;
}
child.get(choiceC - 1).setorphan(temporphan);
System.out.println(inputorphan + " has been updated.");
} else if (choiceC2 == 10) {
System.out.println("Exiting Update.");
} else {
System.out.println("Invalid Input.");
}
}
}
// update text
saveFile();
//clear buffer
in1.nextLine();
sc.nextLine();
a1.nextLine();
a2.nextLine();
}
/*
* FUNCTION NAME : deleteHomeless
* DESCRIPTION : delete homeless people from the list
* AUTHOR : Brendan Dylan Gampa anak Joseph Dusit@Dusit A20EC0021
*/
static void deleteHomeless() throws Exception {
System.out.println("<<< DELETE HOMELESS PEOPLE >>>");
printLine();
// validation for category
if (adult.size() == 0 && child.size() == 0) {
System.out.println("No Homeless People Available!");
System.out.println();
} else {
System.out.println("Please select which category you want to delete");
printLine();
System.out.println("ADULT - A");
System.out.println("CHILD - C");
printLine();
System.out.print("Option :: ");
category = in1.next().charAt(0);
in1.nextLine(); // clear buffer
Clrscr();
if (Character.toUpperCase(category) == 'A') {
if (adult.size() == 0) {
System.out.println("No adult list to be deleted");
} else {
int numA = 1;
System.out.printf("%-3s %-15s %-10s %-6s %-40s %-15s %-10s %-15s", "No",
"Full name", "Gender", "Age",
"Location", "Days stayed", "Adult ID", "Past Occupation");
System.out.println();
printLine();
for (int i = 0; i < adult.size(); i++) {
System.out.printf("[%-1s] %-15s %-10s %-6s %-40s %-15s %-10s %-15s",
numA, adult.get(i).getName(), adult.get(i).getGender(),
adult.get(i).getAge(), adult.get(i).getLocation(),
adult.get(i).getStayDays(), adult.get(i).getAdultID(),
adult.get(i).getOccup());
System.out.println();
numA++;
}
System.out.println();
System.out.print("Choose Adult To Delete: ");
choiceA = in1.nextInt();
System.out.println("Adult " + adult.get(choiceA - 1).getName() + " has been deleted.");
adult.remove(choiceA - 1);
System.out.println();
}
} else if (Character.toUpperCase(category) == 'C') {
if (child.size() == 0) {
System.out.println("No child list to be deleted");
} else {
int numC = 1;
String childstatus = " ";
System.out.printf("%-3s %-15s %-10s %-6s %-40s %-15s %-10s %-15s %-20s",
"No", "Full name", "Gender", "Age", "Location", "Days stayed",
"Child ID",
"Parent Name", "Orphan Status");
System.out.println();
printLine();
for (int i = 0; i < child.size(); i++) {
// verify child status
if (child.get(i).getOrphanStatus() == true) {
childstatus = "Orphan";
} else if (child.get(i).getOrphanStatus() == false) {
childstatus = "Non-orphan";
}
System.out.printf(
"[%-1s] %-15s %-10s %-6s %-40s %-15s %-10s %-15s %-20s",
numC, child.get(i).getName(), child.get(i).getGender(),
child.get(i).getAge(), child.get(i).getLocation(),
child.get(i).getStayDays(), child.get(i).getChildID(),
child.get(i).getParentName(), childstatus);
System.out.println();
numC++;
}
System.out.println();
System.out.print("Choose Child To Delete: ");
choiceC = in1.nextInt();
System.out.println("Child " + child.get(choiceC - 1).getName() + " has been deleted.");
child.remove(choiceC - 1);
System.out.println();
}
}
// save updated text
saveFile();
//clear buffer
in1.nextLine();
}
}
/*
* FUNCTION NAME : displayHomelessPeople
* DESCRIPTION : display homeless people list
* AUTHOR : Brendan Dylan Gampa anak Joseph Dusit@Dusit A20EC0021
*/
static void displayHomelessPeople() {
String childstatus = " ";
System.out.println("<<<< LIST OF REGISTERED HOMELESS PEOPLE >>>>");
printLine();
System.out.println("<<<< ADULT >>>>");
printLine();
if (adult.size() == 0) {
System.out.println("No adult people is registered.");
} else {
int numA = 1;
System.out.printf("%-3s %-15s %-10s %-6s %-40s %-15s %-10s %-15s", "No", "Full name", "Gender", "Age",
"Location", "Days stayed", "Adult ID", "Past Occupation");
System.out.println();
for (int i = 0; i < adult.size(); i++) {
System.out.printf("[%-1s] %-15s %-10s %-6s %-40s %-15s %-10s %-15s",
numA, adult.get(i).getName(), adult.get(i).getGender(),
adult.get(i).getAge(), adult.get(i).getLocation(),
adult.get(i).getStayDays(), adult.get(i).getAdultID(),
adult.get(i).getOccup());
System.out.println();
numA++;
}
}
printLine();
System.out.println("<<<< CHILD >>>>");
printLine();
if (child.size() == 0) {
System.out.println("No child people is registered.");
} else {
int numC = 1;
System.out.printf("%-3s %-15s %-10s %-6s %-40s %-15s %-10s %-15s %-20s",
"No", "Full name", "Gender", "Age", "Location", "Days stayed", "Child ID",
"Parent Name", "Orphan Status");
System.out.println();
for (int i = 0; i < child.size(); i++) {
// verify child status
if (child.get(i).getOrphanStatus() == true) {
childstatus = "Orphan";