-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CS2113-W12-2] FindOurSEP #8
base: master
Are you sure you want to change the base?
Changes from 130 commits
e1ad270
348818f
aac7d97
1fa650f
5d5630c
14b9589
e7266ff
051bb1a
3697b9b
b17b59f
f0cf7e8
840135c
2e20232
5083f45
60b41f6
d0f8fe8
ba4501f
93f21a2
1e51dc6
bf08242
c92eee7
25bbffe
0da562c
17b8b8f
83ef693
14a2723
47276bd
c5ba304
470ee52
1d3b021
4f8c0b7
205c4c0
f033b3c
92152d2
1ab484e
131585b
aa7526b
e542181
0ee0e65
f0b7d45
c9d5a16
fd7f230
64e349d
baa545f
c61453e
5b7ecdb
43db8d6
7583b5f
9aea85f
1fc7d2a
2a7c81b
3cb447a
d413751
6dfeb39
f7221a9
71f5e92
7370cb1
9d57e56
0734bf0
6a5d6da
2930749
54fe49a
76bfbfc
3311f25
305f4dd
cad578b
2266638
64737a0
d74aeb8
ec2aefd
45fbe0a
65784e2
ff0f2b4
65e40c1
f183cf7
07c620f
a212633
86a370c
e6173f6
380a6d1
7520f65
cfa2eb3
5344e16
d2296d0
1092a5f
72bdd35
15a1dac
a6d54e5
0ff5678
4e8f273
c0d3b6b
5a6910b
50d1aa6
30c1f8b
bacc72b
539bebf
52982b6
b3e4cda
9eb20d5
84c7899
a9151b2
b2a2c90
58c8081
84b485f
12d673e
1cbae78
047d3c1
457c20b
60dfe97
2298e85
a01933e
69ed44b
3940984
31872e5
bdd4ae7
1a52460
88df2e8
bb55428
5b01f8e
1a74870
fee9a6c
03148db
9b50602
f0bc2f4
8d696ab
94b2244
1448a12
2dfb024
f790a40
0ddbad5
8f8a75b
3864b3f
e0c113e
c6451a4
ff2214e
e387892
2f575c2
facfbc1
2a77be3
301345b
7e0d590
590a11d
0b814b8
0204e7f
dd82afd
6ffcc4e
040e00b
545c03a
afa2802
b32e352
58b1647
7153ade
e45c67d
5214ee1
67b6bf1
434a022
47928cd
c8a2eaf
e845773
d766704
aeb4b91
1fd9418
a56f642
240f548
2328a81
82f0951
d9d7127
1ed5065
95fd324
ce47c7f
cb95dd5
a33132c
dacd338
61be5a8
8f830c1
0484f6e
0638254
7ace8a4
9a1d6a2
1279967
9022afa
a300e08
61ed33c
36efa27
648e9d1
8abddad
76baa7e
09fda35
32f08ab
6759560
be2538d
92a7ba0
c5b3d51
610b035
5195a68
de7ecb9
d36f9e1
69efab7
6d3a4dc
5591400
955e1d1
413fa21
5f9d345
ebe7c12
f8a4a20
9c28c39
eacb4c1
6038410
1ed3ac2
ed83d8b
c048ad8
78ac0bd
78101b0
2dc8cc7
dcc46d2
2d2060d
d421e7e
ab4f94e
3bcf660
59da8f1
9a49642
88d4050
8a18329
4b90b35
75a306d
5a1d007
a5e0693
8d23bdb
b0c6599
3cdc700
7ffa6b7
cc0605d
2f78a49
7684ca5
d2789cd
de07cfd
57d3955
7bea33a
4329221
bf0550f
82b8aaa
3e38cb5
a704ced
90ca528
de1d5f8
40535f8
65a8760
d5de08f
e13502c
7e2c9b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,6 @@ bin/ | |
|
||
/text-ui-test/ACTUAL.TXT | ||
text-ui-test/EXPECTED-UNIX.TXT | ||
|
||
|
||
*class |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# About us | ||
# About Us | ||
|
||
Display | Name | Github Profile | Portfolio | ||
--------|:----:|:--------------:|:---------: | ||
![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
Display | Name | Github Profile | Portfolio | ||
--------|:-----:|:--------------:|:---------: | ||
![](https://via.placeholder.com/100.png?text=Photo) | Isaac | [Github](https://github.com/isaacsaw25) | ||
![](https://picsum.photos/seed/picsum/200/300) | Lee Hao Zhe | [Github](https://github.com/ehz0ah) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Xiong Xinzhuang | [Github](https://github.com/ThisisXXZ) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Paul Tham | [Github](https://github.com/paulktham) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Anderson Lim | [Github](https://github.com/Holy-An) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great job overall! The code is solid, and the functionality works well. I have a few minor suggestions to improve readability and maintain the single responsibility principle (SRP). SRP: The setMinimumGPA method does a lot—validation, parsing, and setting the GPA. Consider extracting some of that logic into separate methods for clarity. Error handling: The method setMinimumGPA collects errors in a Set. It might be clearer to use a List instead since you're expecting multiple error messages. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package allocator; | ||
|
||
import student.Student; | ||
import studentlist.StudentList; | ||
import university.University; | ||
import university.UniversityRepository; | ||
|
||
import java.util.Set; | ||
|
||
import exceptions.SEPException; | ||
|
||
import java.util.HashSet; | ||
|
||
public class Allocator { | ||
|
||
private static double minimumGPA = 0; | ||
private StudentList studentList; | ||
|
||
|
||
public Allocator(StudentList studentList) { | ||
this.studentList = new StudentList(studentList); // don't want to modify the original list | ||
} | ||
|
||
/* | ||
* setMinimumGPA reuses a helper function found in studentList | ||
* The helper function validateGPA reads a string and ensures that the GPA is a valid one | ||
* Valid referring to the GPA being within the right values of 0.0 to 5.0 | ||
* It then returns a float which we use to set the minimumGPA variable | ||
*/ | ||
|
||
public void setMinimumGPA(String stringGpa) throws SEPException { | ||
Set<String> errorMessages = new HashSet<>(); | ||
|
||
float gpa = studentList.validateGpa(stringGpa, errorMessages); | ||
|
||
if (!errorMessages.isEmpty()) { | ||
throw new SEPException(String.join("\n", errorMessages)); | ||
} | ||
|
||
//Setting the static minimum GPA criteria to the input | ||
minimumGPA = gpa; | ||
} | ||
|
||
public double getMinimumGPA(){ | ||
return minimumGPA; | ||
} | ||
|
||
public StudentList allocate() { | ||
studentList.sortStudentsByGPA(); | ||
for (Student student : studentList.getList()) { | ||
for (int uni : student.getUniPreferences()) { | ||
University university = UniversityRepository.getUniversityByIndex(uni); | ||
if (university.getSpotsLeft() > 0 && student.getGpa() >= minimumGPA) { | ||
university.removeASpot(); | ||
student.setAllocatedUniversity(uni); | ||
student.setSuccessfullyAllocated(true); | ||
break; | ||
} | ||
} | ||
} | ||
studentList.sortStudentsById(); | ||
return studentList; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package command; | ||
|
||
import exceptions.SEPException; | ||
|
||
import student.Student; | ||
import studentlist.StudentList; | ||
import ui.UI; | ||
|
||
public class AddCommand extends Command { | ||
private String input; | ||
private UI ui; | ||
|
||
public AddCommand(StudentList studentList, String input, UI ui) { | ||
super(studentList); | ||
this.input = input; | ||
this.ui = ui; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
Student newStudent = super.studentList.makeStudent(this.input); | ||
super.studentList.addStudent(newStudent); | ||
ui.printResponse("Added " + newStudent.getId() + " successfully.\n" + | ||
"There are " + studentList.getNumStudents() + " student(s) in the list."); | ||
} catch (SEPException e) { | ||
ui.printResponse(e.getMessage()); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package command; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
|
||
import allocator.Allocator; | ||
import studentlist.StudentList; | ||
import ui.UI; | ||
|
||
public class AllocateCommand extends Command { | ||
private Allocator allocator; | ||
private UI ui; | ||
private ExecutorService executor = Executors.newFixedThreadPool(2); // Create a thread pool | ||
|
||
public AllocateCommand(StudentList studentList, UI ui) { | ||
super(studentList); | ||
this.ui = ui; | ||
this.allocator = new Allocator(studentList); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
// Submit the allocation task | ||
Future<StudentList> allocationTask = executor.submit(() -> { | ||
return allocator.allocate(); | ||
}); | ||
|
||
// Submit the loading message task | ||
Future<?> loadingTask = executor.submit(() -> { | ||
while (!allocationTask.isDone()) { | ||
this.ui.printAllocatingMessage(); | ||
} | ||
}); | ||
|
||
// Check periodically if the allocation is done | ||
while (!allocationTask.isDone()) { | ||
Thread.sleep(100); // Small delay to avoid busy-waiting | ||
} | ||
|
||
// Interrupt the loading task once allocation is done | ||
loadingTask.cancel(true); | ||
|
||
// Retrieve the result of the allocation task | ||
this.studentList.setStudentList(allocationTask.get()); | ||
|
||
// Shut down the executor service | ||
executor.shutdown(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could consider only leave spaces between different groups of logics, instead of between every line or block. |
||
} catch (InterruptedException | ExecutionException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package command; | ||
|
||
import studentlist.StudentList; | ||
|
||
/** | ||
* An abstract class representing a command that can be executed by the application. | ||
* Subclasses should override the run() method to provide the implementation of the | ||
* command. | ||
*/ | ||
public abstract class Command { | ||
protected StudentList studentList; | ||
|
||
public Command(StudentList studentList) { | ||
this.studentList = studentList; | ||
} | ||
|
||
/** | ||
* Executes the command. | ||
*/ | ||
public abstract void run(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package command; | ||
|
||
import allocator.Allocator; | ||
import exceptions.SEPException; | ||
import studentlist.StudentList; | ||
import ui.UI; | ||
|
||
public class CriteriaCommand extends Command { | ||
private String input; | ||
private UI ui; | ||
private Allocator allocator; | ||
|
||
public CriteriaCommand (StudentList studentList,String input, UI ui) { | ||
super(studentList); | ||
this.input = input; | ||
this.ui = ui; | ||
this.allocator = new Allocator(studentList); | ||
} | ||
|
||
/* | ||
* Takes the input and sends the second part of the input into the setMinimumGPA function in allocator | ||
*/ | ||
|
||
@Override | ||
public void run() { | ||
try{ | ||
String[] parts = input.split(" "); | ||
allocator.setMinimumGPA(parts[1]); | ||
ui.printResponse("Minimum requirement of GPA set to " + parts[1] + " successfully."); | ||
} catch (SEPException e) { | ||
ui.printResponse(e.getMessage()); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package command; | ||
|
||
import exceptions.SEPException; | ||
import studentlist.StudentList; | ||
import ui.UI; | ||
|
||
public class DeleteCommand extends Command { | ||
private String input; | ||
private UI ui; | ||
|
||
public DeleteCommand(StudentList studentList, String input, UI ui) { | ||
super(studentList); | ||
this.input = input; | ||
this.ui = ui; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
super.studentList.deleteStudent(this.input); | ||
ui.printResponse("Removed student, " + studentList.getNumStudents() + " student(s) left"); | ||
} catch (SEPException e) { | ||
ui.printResponse(e.getMessage()); | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package command; | ||
|
||
import studentlist.StudentList; | ||
import ui.UI; | ||
|
||
public class ExitCommand extends Command { | ||
private UI ui; | ||
|
||
public ExitCommand(StudentList studentList, UI ui) { | ||
super(studentList); | ||
this.ui = ui; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
this.ui.cleanupAndExit(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall there are no major errors with the UML diagrams presented. Good job