-
Notifications
You must be signed in to change notification settings - Fork 0
/
RefereeInterface.java
97 lines (87 loc) · 3.36 KB
/
RefereeInterface.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
import java.io.Serializable;
import java.util.Scanner;
class RefereeInterface extends UserInterface implements Serializable {
private RefereeManager manager;
private JobPostingManager jobPostingManager;
RefereeInterface(Database d) {
manager = new RefereeManager(d.getReferees());
jobPostingManager = new JobPostingManager(d.getAllJobPostings());
}
/**
* Logs in and redirect user to main menu
*/
void login(Database d) {
Scanner console = new Scanner(System.in);
VerifyInput verify = new VerifyInput();
System.out.println("Please enter your username or type cancel to cancel action");
String input = console.next();
if (verify.cancel(input)) {
this.cancel(d);
return;
}
while (!manager.hasReferee(input)) {
System.out.println("This username does not exist. Please try again: (Type cancel to cancel action)");
input = console.next();
if (verify.cancel(input)) {
this.cancel(d);
return;
}
}
Referee referee = manager.getRefereeByUsername(input);
System.out.println("Please enter your password:");
input = verify.attemptPassword(referee);
if (verify.cancel(input)) {
return;
}
System.out.println("Successfully logged in.");
this.MainMenu(d, referee, manager, jobPostingManager);
}
/**
* Create a new account and redirect user to main menu
*/
void newAccount(Database d) {
Scanner console = new Scanner(System.in);
VerifyInput verify = new VerifyInput();
System.out.println("Please enter your first name or cancel to stop:");
String name = console.next();
if (verify.cancel(name)) {
this.cancel(d);
return;
}
System.out.println("Please enter your password (must be at least 3 characters long):");
String password = verify.getValidPassword();
Referee referee = new Referee(name, password, manager, d);
System.out.println("Account created. Please note that your username is: " + referee.getUserName());
System.out.println("Also note that your userID is: " + referee.getId());
System.out.println("Logging in...");
this.MainMenu(d, referee, manager, jobPostingManager);
}
/**
* Allows user to do certain actions based on user type
*/
private void MainMenu(Database d, Referee r, RefereeManager refereeManager, JobPostingManager jp) {
d.saveAllReferees(refereeManager);
VerifyInput verify = new VerifyInput();
System.out.println("===Main Menu===");
System.out.println();
System.out.println("What would you like to do today?");
System.out.println("1: Upload a reference letter for a applicant, 2: See due dates of jobs 3: logout");
int input = verify.getValidChoice(3);
switch (input) {
case 1:
r.upLoadReferenceLetter(d);
break;
case 2:
r.seeDueDatesOfJobs(jp);
break;
case 3:
Main.Welcome(d);
return;
}
this.MainMenu(d, r, refereeManager, jp);
}
private void cancel(Database d) {
System.out.println("Action canceled.");
Main.Welcome(d);
}
}