-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicantMenu.java
More file actions
123 lines (100 loc) · 4.02 KB
/
ApplicantMenu.java
File metadata and controls
123 lines (100 loc) · 4.02 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
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Set;
/**
* <h3> COMP90041, Sem2, 2022: Final Project </h3>
* <p> Class ApplicantMenu has methods to take user input for tag applicant and call the required methods.
* @author Gia Han Ly
*
*/
public class ApplicantMenu {
private static final Set<String> CHOICE = Set.of("create", "jobs", "quit", "c", "j", "q");
private Jobs jobs = new Jobs();
private Applicant applications = new Applicant();
private ArrayList<Long> jobsApp = new ArrayList<>();
private Scanner keyboard = null;
// Constructors
/**
* Constructor for ApplicantMenu
* @param jobsFile jobs file name
* @param applicationsFile applications file name
*/
public ApplicantMenu(String jobsFile, String applicationsFile){
jobs.read(jobsFile);
applications.setApplicantionsFile(applicationsFile);
}
/**
* Get user input from command line input. Call the required methods of jobs and applicant type.
* Available input are: create application, quit, list available jobs and apply.
*/
public void getInput(){
keyboard = new Scanner(System.in);
menu(0);
String input;
while (true){
input = keyboard.nextLine();
if (!CHOICE.contains(input)){
System.out.print("Invalid input! Please enter a valid command to continue:\n> ");
}
if (input.equals("c") || input.equals("create")){
applications = applications.create(keyboard);
Applicant.saveApplicant(applications);
jobs.writeName(applications.getLastname(), applications.getFirstname(), applications.getCreatedAt());
menu(1);
}
if (input.equals("q") || input.equals("quit")){
jobs.writeJobs();
jobs.writeEnd();
return;
}
if (input.equals("j") || input.equals("jobs")){
jobs.jobsAvailable();
if (applications.getLastname() == null){
menu(0);
continue;
}
if (Jobs.getNumberofJobs() == 0){
menu(1);
continue;
}
System.out.print("Please enter the jobs you would like to apply for (multiple options are possible): ");
while (true){
input = keyboard.nextLine();
String[] jchoices = input.split(",");
try {
for (String c : jchoices){
int num = Integer.parseInt(c);
if (num > Jobs.getNumberofJobs()){
throw new NumberFormatException();
}
jobsApp.add(jobs.getCreatedAt(num-1));
}
break;
}
catch (NumberFormatException e){
System.out.print("Invalid input! Please enter a valid number to continue: ");
}
}
jobs.jobsApplied(jobsApp);
menu(1);
}
}
}
/**
* Display main menu for applicant tag
* @param created - whether the application has been created or not, 0 for not yet, 1 for created
*/
private void menu(int created){
String menu = Jobs.getNumberofJobs()+" jobs available. "+ jobsApp.size() +" applications submitted.\n" +
"Please enter one of the following commands to continue:\n";
String create = "- create new application: [create] or [c]\n";
String next = "- list available jobs: [jobs] or [j]\n" +
"- quit the program: [quit] or [q]\n" +
"> ";
System.out.print(menu);
if (created == 0){
System.out.print(create);
}
System.out.print(next);
}
}