-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplied.java
More file actions
145 lines (123 loc) · 4.01 KB
/
Applied.java
File metadata and controls
145 lines (123 loc) · 4.01 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
import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
/**
* <h3>COMP90041, Sem2, 2022: Final Project</h3>
* <p>Class Applied has methods to store jobs and applications for it, as well as display jobs and its applications
*
* @author Gia Han Ly
*/
public class Applied {
private String fileName = "applied.csv";
private Scanner input = null;
protected static ArrayList<ArrayList<Long>> listA = new ArrayList<>();
//Setters and getters
/**
* Get list of jobs and its applications
* @return list contains jobs and its applications
*/
public static ArrayList<ArrayList<Long>> getAppliedList(){
return listA;
}
//Methods
/**
* Load jobs and applications for it
*/
public void loadApplied(){
initialiseList();
createJobsApplicants();
}
/**
* Read in applied file and store jobs with corresponding applications
* The first is always jobID followed by applications
* <table><tr><td>Job1:</td><td>Applicant1, Applicant2,...</td></tr>
* <tr><td>Job2:</td><td>Applicant2</td></tr>
*/
private void createJobsApplicants(){
try{
input = new Scanner(new FileInputStream(fileName));
}
catch (FileNotFoundException e){
return;
}
if(Jobs.getJobsList().size() == 0){
System.out.println("No jobs available.");
return;
}
if (!input.hasNextLine()){
return;
}
String line;
Long app;
while(input.hasNextLine()){
line = input.nextLine();
String[] element = line.split(",");
// Application timestamp
app = Long.parseLong(element[0]);
for (int i = 3; i< element.length; i++ ){
// Job timestamp
long jobCreatedAt = Long.parseLong(element[i]);
for (ArrayList<Long> item : listA){
// If job timestamp matches with job row, add application timestamp
if (jobCreatedAt == item.get(0)){
item.add(app);
break;
}
}
}
}
}
/**
* Initialise jobs applications list by adding jobs rows
*/
public void initialiseList(){
ArrayList<Jobs> listJobs = Jobs.getJobsList();
if (listJobs.size() == 0){
return;
}
for(Jobs j : listJobs ){
ArrayList<Long> apApplied = new ArrayList<>();
apApplied.add(j.getCreatedAt());
listA.add(apApplied);
}
}
/**
* Print out jobs along with applications for it
*/
public void display(){
loadApplied();
int row = 1;
// Print job details
for (ArrayList<Long> item : listA){
for (Jobs j : Jobs.getJobsList()){
if (j.getCreatedAt() == item.get(0)){
System.out.print("["+ row + "] ");
Jobs.printJob(j);
}
}
int c = 0;
// Print applications details
for (int i = 1; i< item.size(); i++){
int num = 0;
for (Applicant a : Applicant.getApplicantsList()){
if (item.get(i) == a.createdAt){
// Print alpha numeric ordering
if (num == 0){
System.out.print(" ["+ Character.toString(97+(c%26))+"] ");
}
else{
System.out.print(" ["+ Character.toString(97+(c%26))+num+"] ");
if (c%26 == 25){
num++;
}
}
Applicant.printApplicant(a);
c++;
}
}
}
row++;
}
}
}