-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInternshipApplication.java
1311 lines (1224 loc) · 61.1 KB
/
InternshipApplication.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
import java.util.ArrayList;
import java.util.Scanner;
import java.util.UUID;
import java.io.Console;
/**
* The InternshipApplication class is a Facade which runs every aspect of the
* internship application. It allows students to search and apply for an
* internship as well as review companies, employers to post jobs and review
* students, and administrators to remove listings, remove accounts, and
* register new administrators.
* @author Joshua DuPuis
*/
public class InternshipApplication {
private User user;
private int permission;
private SearchableDatabase database;
private Scanner scanner;
/**
* The InternshipApplication constructor initializes the facade that will
* run the entire program.
*/
InternshipApplication() {
this.database = DataLoader.loadData();
this.scanner = new Scanner(System.in);
}
public ArrayList<User> getUsers() {
return this.database.getUsers();
}
/**
* The CreateAccount method allows a user to create an account as either an
* employer or student.
*
* @param accountType The type of account to be created
* @return True if the account was successfully made, false otherwise
*/
public boolean createAccount(String accountType) {
System.out.print("Please enter your first name: ");
String firstname = scanner.nextLine();
System.out.print("Please enter your last name: ");
String lastname = scanner.nextLine();
System.out.print("Please enter your email: ");
String email = scanner.nextLine();
UUID newUUID = UUID.randomUUID();
String password = null;
switch(accountType.toLowerCase()) {
case "student":
// Confirm email matches sc.edu and is of sufficient length
while (!(email.substring(email.length() - 6, email.length()).equals("sc.edu")) ) {
System.out.println("Please enter your school email containing \"sc.edu\"");
email = scanner.nextLine();
}
password = confirmPassword();
if(password == null) break;
System.out.println("Enter your year in school (e.g. junior)");
String year = scanner.nextLine();
Student s1 = new Student(firstname,lastname,email,password,year);
database.addUser(s1);
this.user = s1;
user.setUserUUID(UUID.randomUUID());
return true;
case "employer":
password = confirmPassword();
if(password == null) break;
Employer e1 = new Employer(firstname, lastname, email, password);
database.addUser(e1);
this.user = e1;
user.setUserUUID(UUID.randomUUID());
return true;
}
return false;
}
/**
* Private helper method used to handle password creation when creating an account, including confirmation.
* Passwords must be 8 characters or longer.
*
* @return The password of the account, or null if unsuccessful
*/
private String confirmPassword() {
Console console = System.console();
try {
while(true) {
char[] passwordArr = console.readPassword("Please enter the password you want to use (8 or more characters): ");
String passwordAttempt1 = new String(passwordArr);
if(passwordAttempt1.length() < 8) {
System.out.println("Your password must be 8 characters or longer.");
continue;
}
char[] passwordArr2 = console.readPassword("Confirm your password by re-entering it: ");
String passwordAttempt2 = new String(passwordArr2);
if(passwordAttempt1.equals(passwordAttempt2)) {
System.out.println("Password created sucessfully!");
return passwordAttempt2;
}
System.out.println("The passwords you've entered do not match. Try again.");
}
} catch(Exception e) {
System.out.println("You have entered invalid input. Please retry if you want to create an account.");
return null;
}
}
/**
* The logOn method allows a user with an existing account to log on to the
* system. Additionally sets the appropriate instance variables in the InternshipApplication
* for the logged on user.
*
* @param email The User's email attempt
* @param password The User's password attempt
* @return true for a successful login, false otherwise.
*/
public boolean logOn(String email, String password) {
//Assign the right user and permissions if logOn was successful
for(User user : database.getUsers()) {
if(user.getEmail().equals(email) && user.getPassword().equals(password)) {
this.user = user;
permission = this.user.getPermission();
return true;
}
}
return false;
}
/**
* The logOff method logs a user out of the system once they are finished
* using it. Writes current database data to JSON files through the DataWriter class.
*/
public void logOff() {
System.out.println("\nLogging off...");
DataWriter.saveUsers();
DataWriter.saveCompanyProfiles();
DataWriter.saveJobListings();
}
/**
* This search method allows a user to search through all of the internship
* listings to find one to apply for if they are a student or update if
* they are an employer
* @param title The title of the JobListing the user is looking for
* @return Returns all of the JobListings with the title entered by
* the user
*/
public ArrayList<JobListing> search(String title) {
ArrayList<JobListing> search_result = new ArrayList<JobListing>();
search_result = database.searchListings(title);
return search_result;
}
/**
* This search method allows a user to search through all of the internship
* listings by pay rate, starting with a specified minimum.
*
* @param payRate The title of the JobListing the user is looking for
* @return Returns all of the JobListings that meet or exceed the rate entered by
* the user
*/
public ArrayList<JobListing> search(double payRate) {
ArrayList<JobListing> search_result = new ArrayList<JobListing>();
search_result = database.searchListingsbyPay(payRate);
return search_result;
}
/**
* The searchBySkill method searches the database for any job listings that have the
* specified skill as a required skill.
* @param skill The name of the skill desired
* @return The ArrayList of all job listings with the given skill
*/
public ArrayList<JobListing> searchBySkill(String skill) {
ArrayList<JobListing> search_result = database.searchListingsBySkill(skill);
return search_result;
}
/**
* This sort method allows a user to alphabetically sort the listings from the database.
*/
public void sortAlphabetically() {
database.sortListingsAlphabetically();
}
/**
* This sort method allows a user to sort the listings through pay rate.
*/
public void sortPayRate() {
database.sortListingsbyPay();
}
/**
* The editPersonalInfo method allows a user to edit the personal
* information associated with their account
*/
public void editPersonalInfo() {
System.out.println("Your Personal Information:\nFirst name: " + user.getFirstName() + "\nLast Name: " + user.getLastName() + "\nEmail: " + user.getEmail() + "\nPassword: " + user.getPassword());
System.out.println("What would you like to edit?");
System.out.println("[F]irst name\n[L]ast name\n[E]mail\n[P]assword");
try {
String answer = scanner.nextLine().toLowerCase();
switch(answer) {
case "f":
System.out.println("What would you like your first name to be?");
String newFirstName = scanner.nextLine();
user.editFirstName(newFirstName);
System.out.println("The first name on your account is: " + user.getFirstName());
break;
case "l":
System.out.println("What would you like your last name to be?");
String newLastName = scanner.nextLine();
user.editLastName(newLastName);
System.out.println("The last name on your account is: " + user.getLastName());
break;
case "e":
System.out.println("What would you like your email to be?");
String newEmail = scanner.nextLine();
if(newEmail.length() < 3) {
System.out.println("Email is too short. Returning...\n");
}
//If it's a student changing their email address, check for .edu
if(permission == 0 && !(newEmail.substring(newEmail.length()-6).equals("sc.edu"))) {
System.out.println("Your new email must still be one associated with the university.");
return;
}
user.editEmail(newEmail);
System.out.println("The email on your account is: " + user.getEmail());
break;
case "p":
System.out.println("What would you like your new password to be?");
String newPassword = scanner.nextLine();
if(newPassword.length() < 8) {
System.out.println("Your password must be 8 characters or longer.");
return;
}
user.editPassword(newPassword);
System.out.println("The password on your account is: " + user.getPassword());
break;
default:
System.out.println("You entered an option that wasn't listed. Restart this command if you want to try again.\n");
return;
}
} catch(Exception e) {
System.out.println("You've entered invalid input. Restart the command to try again.\n");
}
}
/**
* The writeReview method allows either an employer or a student to write a
* review.
*/
public void writeReview() {
try {
if (permission > 1 || permission < 0) {
System.out.println("You don't have valid permissions to use this command.\n");
return;
}
//Student leaving a review on a company profile
else if(permission == 0) {
Student student = (Student) this.user;
System.out.print("Enter the name of the company you'd like to review: ");
ArrayList<CompanyProfile> companyChoices = database.searchProfiles(scanner.nextLine());
if(companyChoices.isEmpty()) {
System.out.println("No companies were found with the given name. Retry this command if you want to try again.\n");
return;
}
formatCompanyProfiles(companyChoices);
System.out.println("If any of these choices match the company you want to review, enter the number listed beside it. Enter 0 to exit.");
int index = getUserCommand(companyChoices.size());
if(index == -1) {
System.out.println("Returning...\n");
return;
}
else {
CompanyProfile companyToReview = companyChoices.get(index);
System.out.print("On a scale of 1 to 5 (no decimals), what is your rating of the company (e.g. 3)? ");
int rating = scanner.nextInt();
scanner.nextLine();
if(rating > 5 || rating < 1) {
System.out.println("You entered an invalid rating. The review could not be created.\n");
return;
}
System.out.println("Enter the comment you would like to leave with your review: ");
String comment = scanner.nextLine().trim();
student.reviewCompany(rating, comment, companyToReview);
System.out.println("Your review for " + companyToReview.getCompanyName() + " has been made successfully. Returning...\n");
}
}
//Employer leaving review on a student profile
else {
Employer employer = (Employer) this.user;
Student student = null;
System.out.print("Enter the email of the student you'd like to leave a review for: ");
String studentEmail = scanner.nextLine();
for(User user : database.getUsers()) {
if(user.getPermission() == 0 && user.getEmail().equals(studentEmail)) {
student = (Student) user;
}
}
if(student == null) {
System.out.println("No student account has the email you've provided.\n");
return;
}
System.out.print("On a scale of 1 to 5 (no decimals), what is your rating of the student (e.g. 3)? ");
int rating = scanner.nextInt();
scanner.nextLine();
if(rating > 5 || rating < 1) {
System.out.println("You entered an invalid rating. The review could not be created.\n");
return;
}
System.out.println("Enter the comment you would like to leave with your review: ");
String comment = scanner.nextLine().trim();
employer.reviewStudent(rating, comment, student);
System.out.println("Your review for " + student.getFirstName() + " " +
student.getLastName() + " has been made successfully. Returning...\n");
}
} catch(Exception e) {
System.out.println("You entered invalid input. Retry the command to try again.\n");
}
}
/**
* Private helper method used to print out cleanly formatted and descriptive JobListings, including visibility.
* @param reviews The ArrayList of listings to print out
*/
private void formatCompanyProfiles(ArrayList<CompanyProfile> companies) {
int companiesSize = companies.size();
System.out.println(companiesSize + " listing(s) available:\n");
for(int i = 1; i <= companiesSize; i++) {
CompanyProfile company = companies.get(i-1);
System.out.println("\t" + i + ". " + company.toString() + "\n");
}
}
/**
* The createResume method allows a student user to create a resume that
* employers can view when the student applies for a job
*/
public void createResume() {
if(permission != 0) {
System.out.println("You don't have valid permissions to use this command.\n");
return;
}
Student student = (Student) this.user;
ArrayList<Integer> skillIndexes = new ArrayList<>();
ArrayList<Integer> classIndexes = new ArrayList<>();
ArrayList<WorkExperience> workExperiences = new ArrayList<>();
ArrayList<Education> educations = new ArrayList<>();
System.out.println("Resumes require skills and classes to be added to your profile.\n"
+ "Please enter any skills you'd like to add to your account profile (one at a time), or enter \"0\" to continue."
+ "\nThese are the current skills on your profile: " + student.getSkills());
String input = scanner.nextLine();
while (!(input.equals("0"))) {
if (student.getSkills().contains(input)) {
System.out.println("That skill is already in your profile.");
} else {
student.addSkill(input);
}
System.out.println("Enter another skill, or enter \"0\" to continue.");
input = scanner.nextLine();
}
System.out.println("Please enter any classes you'd like to add to your account profile (one at a time), or enter \"0\" to continue."
+ "\nThese are the current classes on your profile: " + student.getClasses());
input = scanner.nextLine();
while (!(input.equals("0"))) {
if (student.getClasses().contains(input)) {
System.out.println("That class is already in your profile.");
} else {
student.addClass(input);
}
System.out.println("Enter another class, or enter \"0\" to continue.");
input = scanner.nextLine();
}
try {
//Get appropriate skills
System.out.println("Which skills would you like to add to your resume? Enter the name of each skill one at a time, and type 0 when done.");
System.out.println("These are your current skills: " + student.getSkills());
String skillName = scanner.nextLine();
while(!skillName.equals("0")) {
int skillIndex = student.getSkillIndex(skillName);
if(skillIndex != -1) {
skillIndexes.add(skillIndex);
System.out.println("Skill added successfully.");
}
else {
System.out.println("That skill isn't on your profile. Be sure to add any new skills to your profile first!"
+ "\nEnter the name of each skill (one at a time), and type 0 when done.");
}
skillName = scanner.nextLine();
}
//Get appropriate classes
System.out.println("Which classes would you like to add to your resume? Enter the name of each class one at a time, and type 0 when done.");
System.out.println("These are your current classes: " + student.getClasses());
String className = scanner.nextLine();
while(!className.equals("0")) {
int classIndex = student.getClassIndex(className);
if(classIndex != -1) {
classIndexes.add(classIndex);
System.out.println("Class added successfully.");
}
else {
System.out.println("That class isn't on your profile. Be sure to add any new classes to your profile first!"
+ "\nEnter the name of each class (one at a time), and type 0 when done.");
}
className = scanner.nextLine();
}
//Create work experiences
System.out.print("Would you like to add any work experiences [Y/N]? ");
String yesNoOption = scanner.nextLine().toLowerCase();
int count = 1;
while(!yesNoOption.equals("n")) {
if(yesNoOption.equals("y")) {
System.out.println("Work Experience #" + count + ":");
System.out.print("\tWhat is the title of this work experience? ");
String jobTitle = scanner.nextLine();
System.out.print("\tWhat is the company/organization you worked for? ");
String company = scanner.nextLine();
System.out.print("\tProvide the date range of this experience (e.g. 7/7/21-8/7/21): ");
String dateRange = scanner.nextLine();
System.out.print("\tGive a description of this work experience: ");
String description = scanner.nextLine();
workExperiences.add(new WorkExperience(jobTitle, company, dateRange, description));
System.out.print("\nWork experience #" + count++ + " has been added. Would you like to add another [Y/N]? ");
}
else {
System.out.print("You entered an answer that wasn't Y or N. Try again: ");
}
yesNoOption = scanner.nextLine().toLowerCase();
System.out.println();
}
//Create Educations
System.out.print("Would you like to add any education (colleges, major, gpa, etc.) [Y/N]? ");
yesNoOption = scanner.nextLine().toLowerCase();
count = 1;
while(!yesNoOption.equals("n")) {
if(yesNoOption.equals("y")) {
System.out.println("Education Item #" + count + ":");
System.out.print("\tWhat university/college did you attend? ");
String nameOfUniversity = scanner.nextLine();
System.out.print("\tWhat is/was your major at said university/college? ");
String major = scanner.nextLine();
System.out.print("\tWhat was your GPA there? (e.g. 2.45, 4.00): ");
double gpa = scanner.nextDouble();
scanner.nextLine();
System.out.print("\tWhat is your expected grad date (or actual grad date if graduated) (e.g. Spring 2024)? ");
String expectedGradDate = scanner.nextLine();
educations.add(new Education(nameOfUniversity, major, gpa, expectedGradDate));
System.out.print("\nEducation Item #" + count++ + " has been added. Would you like to add another [Y/N]? ");
}
else {
System.out.print("You entered an answer that wasn't Y or N. Try again: ");
}
yesNoOption = scanner.nextLine().toLowerCase();
}
student.createResume(skillIndexes, classIndexes, workExperiences, educations);
System.out.println("Your resume was created successfully and has been added to your profile! Returning...\n");
} catch(Exception e) {
System.out.println("You entered invalid input. Retry the command to try again.\n");
}
}
/**
* The editResume method allows a student to edit information on their
* resume by overwriting it with a new one.
*/
public void editResume() {
if(permission != 0) {
System.out.println("You don't have valid permissions to use this command.\n");
return;
}
Student student = ((Student)user);
boolean editingResume = true;
while(editingResume) {
System.out.println("Your current resume:\n" + student.getResume().toString());
System.out.println("What would you like to edit on your resume?");
System.out.println("1. Skills\n2. Previous Work Experiences\n3. Education\n4. Classes\n5. Return to Main Menu");
System.out.println("Please enter the number of your preferred action: ");
String input = scanner.nextLine();
switch(input) {
case("1"):
System.out.println("Skills in your profile: " + student.getSkills());
System.out.println("Please enter \"1\" to add a skill to your resume, \"2\" to remove a skill from your resume, or \"3\" to go back:");
String input2 = scanner.nextLine();
switch (input2) {
case("1"):
System.out.println("Please enter a skill to add to your resume");
String newSkill = scanner.nextLine();
if (student.getSkills().indexOf(newSkill) == -1) {
student.addSkill(newSkill);
}
if (student.getResume().getSkills().indexOf(newSkill) != -1) {
System.out.println("You entered a skill that is already on your resume. Returning to previous screen.");
break;
}
student.getResume().addSkill(newSkill);
break;
case("2"):
System.out.println("Please enter a skill to remove from your resume");
String removeSkill = scanner.nextLine();
if (student.getResume().getSkills().indexOf(removeSkill) == -1) {
System.out.println("You entered a skill that isn't on your resume. Returning to previous screen.");
break;
}
student.getResume().removeSkill(removeSkill);
break;
case("3"):
break;
}
break;
case("2"):
System.out.println("Work experiences on your resume: ");
ArrayList <WorkExperience> experiences = student.getResume().getExperiences();
for (WorkExperience exp: experiences) {
System.out.println(exp.toString());
}
System.out.println("Please enter \"1\" to add a Work Experience to your resume, \"2\" to remove a Work Experience from your resume, or \"3\" to go back:");
String input3 = scanner.nextLine();
switch (input3) {
case("1"):
System.out.print("\tWhat is the title of your new work experience? ");
String jobTitle = scanner.nextLine();
System.out.print("\tWhat is the company/organization you worked for? ");
String company = scanner.nextLine();
System.out.print("\tProvide the date range of this experience (e.g. 7/7/21-8/7/21): ");
String dateRange = scanner.nextLine();
System.out.print("\tGive a description of this work experience: ");
String description = scanner.nextLine();
student.getResume().addExperience(new WorkExperience(jobTitle, company, dateRange, description));
break;
case("2"):
System.out.println("What is the title of the work experience you would like to remove?");
String removeJob = scanner.nextLine();
for (WorkExperience exp: experiences) {
if (exp.getJobTitle().equals(removeJob)) {
student.getResume().removeExperience(exp);
break;
}
}
break;
case("3"):
break;
}
break;
case("3"):
System.out.println("Education on your resume: ");
ArrayList <Education> education = student.getResume().getEducation();
for (Education edu: education) {
System.out.println(edu.toString());
}
System.out.println("Please enter \"1\" to add an Education to your resume, \"2\" to remove an Education from your resume, or \"3\" to go back:");
String input4 = scanner.nextLine();
switch (input4) {
case("1"):
System.out.print("\tWhat university/college did you attend? ");
String nameOfUniversity = scanner.nextLine();
System.out.print("\tWhat is/was your major at said university/college? ");
String major = scanner.nextLine();
System.out.print("\tWhat was your GPA there? (e.g. 2.45, 4.00): ");
double gpa = scanner.nextDouble();
scanner.nextLine();
System.out.print("\tWhat is your expected grad date (or actual grad date if graduated) (e.g. Spring 2024)? ");
String expectedGradDate = scanner.nextLine();
student.getResume().addEducation(new Education(nameOfUniversity, major, gpa, expectedGradDate));
break;
case("2"):
System.out.println("What is the name of the university of the education you would like to remove?");
String removeEducation = scanner.nextLine();
for (Education edu: education) {
if (edu.getName().equals(removeEducation)) {
student.getResume().removeEducation(edu);
break;
}
}
break;
case("3"):
break;
}
break;
case("4"):
System.out.println("Classes in your profile: " + student.getClasses());
System.out.println("Please enter \"1\" to add a class to your resume, \"2\" to remove a class from your resume, or \"3\" to go back:");
String input5 = scanner.nextLine();
switch (input5) {
case("1"):
System.out.println("Please enter a class to add to your resume");
String newClass = scanner.nextLine();
if (student.getClasses().indexOf(newClass) == -1) {
student.addClass(newClass);
}
if (student.getResume().getClasses().indexOf(newClass) != -1) {
System.out.println("You entered a class that is already on your resume. Returning to previous screen.");
break;
}
student.getResume().addClass(newClass);
System.out.println();
break;
case("2"):
System.out.println("Please enter a class to remove from your resume");
String removeClass = scanner.nextLine();
if (student.getResume().getClasses().indexOf(removeClass) == -1) {
System.out.println("You entered a class that isn't on your resume. Returning to previous screen.");
break;
}
student.getResume().removeClass(removeClass);
break;
case("3"):
break;
}
break;
case("5"):
System.out.println("Returning to main menu");
editingResume = false;
break;
}
}
}
/**
* The viewResume method allows a student to view their resume.
*/
public void viewResume() {
if(permission != 0) {
System.out.println("You don't have valid permissions to use this command.\n");
return;
}
Student student = (Student) user;
if(student.getResume() == null) {
System.out.println("You have not created a resume yet. You can only view your resume once you've made one!\n");
return;
}
System.out.println("\n" + student.getResume().toString());
}
/**
* The printResumeToFile method allows a student to print the contents of their resume
* to a text file called "resume.txt".
*/
public void printResumeToFile() {
if(permission != 0) {
System.out.println("You don't have valid permissions to use this command.\n");
return;
}
Student student = (Student) user;
student.getResume().toFile();
System.out.println("\nYour resume was successfully printed to 'resume.txt'!\n");
}
/**
* The createJobListing method allows an employer to create a Job Listing
* that students can apply for on their company profile.
*/
public void createJobListing(){
if(permission != 1) {
System.out.println("You don't have valid permissions to use this command.\n");
return;
}
Employer employer = (Employer) this.user;
CompanyProfile company = employer.getCompany();
if(company == null) {
System.out.println("You currently have no company listed on your profile. Create a new company profile or associate with " +
"a pre-existing one before creating a job listing.");
return;
}
try {
System.out.print("What is the title of the listing? ");
String title = scanner.nextLine();
System.out.print("What is the description of the listing? ");
String description = scanner.nextLine();
System.out.print("Where is the job/internship being offerred (e.g. Online, Five Points, etc.)? ");
String location = scanner.nextLine();
System.out.print("What is the pay rate for the position in dollars per hour (e.g. 7.25)? If unpaid, enter 0: ");
double payRate = scanner.nextDouble();
scanner.nextLine();
boolean paid = (payRate <= 0.00);
JobListing jobListingToAdd = new JobListing(title, description, location, paid, payRate, company.getCompanyName());
jobListingToAdd.setUUID(UUID.randomUUID());
company.addListing(jobListingToAdd);
System.out.println("Your listing has been added. Be sure to add any required skills by editing your listing back at the home menu!\n");
} catch(Exception e) {
System.out.println("You entered invalid input. Retry the command to try again.\n");
}
}
/**
* The editJobListing method allows an employer to edit the description of
* an existing job listing and change its visibility setting
* @param jobListing The jobListing the employer wants to edit
*/
public void editJobListing() {
if(permission != 1) {
System.out.println("You don't have valid permissions to use this command.\n");
return;
}
Employer employer = (Employer) this.user;
ArrayList<JobListing> companyListings = employer.getCompany().getListings();
if(companyListings.isEmpty()) {
System.out.println("There are no listings to edit on your company profile.\n");
return;
}
try {
System.out.print("Please enter the number of the listing you would you like to edit the information of: ");
formatListingVisibilities(companyListings);
int listingChoice = getUserCommand(companyListings.size());
JobListing listingToEdit = companyListings.get(listingChoice);
System.out.println("What would you like to edit?");
System.out.println("Title\n" + "Description\n" + "Location\n" + "Pay Rate\n" + "Visibility\n" + "Skills\n");
String answer = scanner.nextLine().toLowerCase();
switch(answer) {
case "title":
System.out.println("What would you like the title to be?");
String newTitle= scanner.nextLine();
listingToEdit.editTitle(newTitle);
break;
case "description":
System.out.println("What would you like the description to be?");
String newDescription = scanner.nextLine();
listingToEdit.editDescription(newDescription);
break;
case "location":
System.out.println("What would you like the location to be?");
String newLocation = scanner.nextLine();
listingToEdit.editLocation(newLocation);
break;
case "pay rate":
case "payrate":
System.out.println("What would you like the pay rate to be (in $/hour, e.g. 7.25)?");
double newPayRate = scanner.nextDouble();
scanner.nextLine();
listingToEdit.editPayRate(newPayRate);
break;
case "visibility":
System.out.println("Toggling visibility...");
listingToEdit.setVisibility(!listingToEdit.getVisibility());
break;
case "skill":
case "skills":
editJobListingSkills(listingToEdit);
break;
default:
System.out.println("You entered an option that wasn't listed. Restart this command if you want to try again\n.");
return;
}
} catch(Exception e) {
System.out.println(e);
System.out.println("You entered invalid input. Retry the command to try again.\n");
}
}
/**
* Private helper method which prompts the user to add or remove skills from a job listing.
* @param listing
*/
private void editJobListingSkills(JobListing listing) {
System.out.println("These are the current skills: " + listing.getRequiredSkills());
boolean input = true;
while(input) {
System.out.println("Would you like to [A]dd or [R]emove a skill? Type 'A' to add, 'R' to remove, or 'Q' to quit.");
try {
String choice = scanner.nextLine().toLowerCase();
switch(choice) {
case("a"):
System.out.print("Enter the name of the skill you want to add: ");
listing.addRequiredSkill(scanner.nextLine());
break;
case("r"):
if(listing.getRequiredSkills().isEmpty()) {
System.out.println("There are no skills to remove.");
break;
}
System.out.print("Enter the name of the skill you want to remove: ");
listing.removeRequiredSkill(scanner.nextLine());
break;
case("q"):
System.out.println("Returning...\n");
input = false;
default:
System.out.println("You entered an invalid option. Try again.");
}
System.out.println("These are the current skills: " + listing.getRequiredSkills());
} catch(Exception e) {
System.out.println("You entered invalid input. Retry the command to try again.\n");
}
}
}
public void viewJobListingApplicants() {
if(permission != 1) {
System.out.println("You don't have valid permissions to do this.\n");
return;
}
Employer employer = (Employer) this.user;
ArrayList<JobListing> employerListings = employer.getCompany().getListings();
if(employerListings.isEmpty()) {
System.out.println("You must have pre-existing job listings before you can view the applicants for them!\n");
return;
}
formatListingVisibilities(employerListings);
System.out.println("Please enter the number of the listing you would like to view the applicants of, or 0 to go back: ");
int listingChoice = Integer.parseInt(scanner.nextLine()) - 1;
while(listingChoice != -1) {
if(listingChoice < -1 || listingChoice >= employerListings.size() + 1) {
System.out.println("You chose a listing that wasn't listed. Try again with a valid choice, or type 0 to go back.");
}
else {
//If its a valid choice, attempt to view applicants
JobListing chosenListing = employerListings.get(listingChoice);
ArrayList<Student> chosenApplicants = chosenListing.getApplicants();
if(chosenApplicants.isEmpty()) {
System.out.println("The selected job listing currently has no applicants to view.\n");
}
else {
for(Student applicant : chosenApplicants) {
System.out.println(applicant.toString() + "\n---------------------------");
}
}
System.out.print("If you'd like to view applicants of another listing, enter the number of the listing; 0 to go back: ");
}
listingChoice = Integer.parseInt(scanner.nextLine()) - 1;
}
System.out.println(); //For formatting
}
/**
* The toggleJobListingVisibility method allows an employer to toggle the visibility setting
* of a given jobListing.
*/
public void toggleJobListingVisibility() {
if(permission != -1) {
System.out.println("You don't have valid permissions to do this.\n");
return;
}
try {
ArrayList<JobListing> currentListings = database.getJobListings();
System.out.println("Please enter the number of the listing you would like to toggle the visibility of, or 0 to go back: ");
formatListingVisibilities(currentListings);
int listingChoice = Integer.parseInt(scanner.nextLine()) - 1;
while(listingChoice != -1) {
if(listingChoice < -1 || listingChoice >= currentListings.size() + 1) {
System.out.println("You chose a listing that wasn't listed. Try again with a valid choice, or type 0 to go back.");
}
else {
//If its a valid choice, toggle the visibility
JobListing chosenListing = currentListings.get(listingChoice);
boolean currentVisibility = chosenListing.getVisibility();
chosenListing.setVisibility(!currentVisibility);
if(!currentVisibility) {
System.out.println("The chosen listing is now visible.");
}
else {
System.out.println("The chosen listing is now hidden.");
}
System.out.print("If you'd like to toggle the visibility of another listing, enter the number of the internship; 0 to go back: ");
}
listingChoice = Integer.parseInt(scanner.nextLine()) - 1;
}
} catch(Exception e) {
System.out.println("You've entered invalid input.");
}
System.out.println("\nReturning...\n");
}
/**
* Private helper method used to print out cleanly formatted and descriptive JobListings, including visibility.
* @param listings The ArrayList of listings to print out
*/
private void formatListingVisibilities(ArrayList<JobListing> listings) {
int listingsSize = listings.size();
if(listingsSize == 0) {
System.out.println("There are no job listings at this time...\n");
return;
}
else {
System.out.println(listingsSize + " listing(s) available:\n");
}
for(int i = 1; i <= listingsSize; i++) {
JobListing jobListing = listings.get(i-1);
System.out.println(i + ". " + jobListing.toStringSummary() +
"\n\tVisibility: " + jobListing.getVisibility() + "\n");
}
}
/**
* The toggleJobListingVisibility method allows an employer to toggle the visibility setting
* of a given jobListing.
*/
public void toggleReviewVisibility() {
if(permission != -1) {
System.out.println("You don't have valid permissions to do this.\n");
return;
}
try {
System.out.println("Are you changing the visibility of a review on a [S]tudent profile or a [C]ompany profile? Enter 'S' or 'C' for your choice: ");
String reviewLocation = scanner.nextLine().toLowerCase();
int reviewChoice;
switch(reviewLocation) {
case("s"):
System.out.print("What's the email of the student? ");
String emailInput = scanner.nextLine();
Student student = null;
for(User user : database.getUsers()) {
if(user.getEmail().equals(emailInput) && user.getPermission() == 0) {
student = (Student) user;
}
}
if(student == null) {
System.out.println("No student account was found with that email.\n");
return;
}
ArrayList<Review> studentReviews = student.getReviews();
if(studentReviews.isEmpty()) {
System.out.println("There are no reviews on the student profile to toggle. Returning...\n");
return;
}
for (int i = 0; i < studentReviews.size(); i++) {
System.out.println((i+1) + ". " + studentReviews.get(i).toString() + "\nVisible: " + studentReviews.get(i).getVisibility());
}
System.out.print("Please enter the number of the review to toggle the visibility of: ");
reviewChoice = getUserCommand(studentReviews.size());
if(reviewChoice == -1) {
System.out.println("You chose an option that doesn't exist. Restart the command if you want to try again.\n");
return;
}
else {
studentReviews.get(reviewChoice).toggleVisibility();
System.out.println("The chosen review's visibility has been toggled.");
return;
}
case("c"):
System.out.print("What's the name of the company? ");
String companyName = scanner.nextLine();
ArrayList<CompanyProfile> results = database.searchProfiles(companyName);
if(results.isEmpty()) {
System.out.println("No company profiles match the given name. Restart the command if you want to try again.\n");
return;
}
System.out.println("Which company is the one you'll be toggling the review visibility for?");
for(int i = 1; i <= results.size(); i++) {
System.out.println( i + ". " + results.get(i-1).getCompanyName() + "\n");
}
int profileIndex = getUserCommand(results.size());
if(profileIndex == -1) {
System.out.println("You chose an option that doesn't exist. Restart the command if you want to try again.\n");
return;
}
CompanyProfile profileChoice= results.get(profileIndex);
ArrayList<Review> profileReviews = profileChoice.getReviews();
if(profileReviews.isEmpty()) {
System.out.println("There are no reviews on the company profile to toggle. Returning...\n");
}
for (int i = 0; i < profileReviews.size(); i++) {
System.out.println((i+1) + ". " + profileReviews.get(i).toString() + "\nVisible: " + profileReviews.get(i).getVisibility());
}
System.out.print("Please enter the number of the review to toggle the visibility of: ");
reviewChoice = getUserCommand(profileReviews.size());
if(reviewChoice == -1) {
System.out.println("You chose an option that doesn't exist. Restart the command if you want to try again.\n");
return;
}
else {
profileReviews.get(reviewChoice).toggleVisibility();
System.out.println("The chosen review's visibility has been toggled.");
return;
}