- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
Latest commit
53 lines (42 loc) · 1.26 KB
/
Copy pathSolution.java
File metadata and controls
53 lines (42 loc) · 1.26 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
importjava.util.Comparator;
importjava.util.PriorityQueue;
classStudent {
privatefinalintid;
privatefinalStringname;
privatefinaldoublecgpa;
publicStudent(intid, Stringname, doublecgpa) {
this.id = id;
this.name = name;
this.cgpa = cgpa;
}
publicintgetID() {
returnid;
}
publicStringgetName() {
returnname;
}
publicdoublegetCGPA() {
returncgpa;
}
}
classPriorities {
privatefinalPriorityQueue<Student> queue = newPriorityQueue<>(
Comparator.comparing(Student::getCGPA).reversed()
.thenComparing(Student::getName)
.thenComparing(Student::getID));
publicList<Student> getStudents(List<String> events) {
events.forEach((event) -> {
if (event.equals("SERVED")) {
queue.poll();
} else {
String[] details = event.split(" ");
queue.add(newStudent(Integer.parseInt(details[3]), details[1], Double.parseDouble(details[2])));
}
});
List<Student> students = newArrayList<>();
while (!queue.isEmpty()) {
students.add(queue.poll());
}
returnstudents;
}
}