Skip to content

Commit

Permalink
Minor refactor to output statements (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanlohyr authored Nov 13, 2023
1 parent d81195a commit d636391
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 24 deletions.
21 changes: 6 additions & 15 deletions src/main/java/seedu/duke/controllers/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void start() throws IOException {
saveStudentData(storageManager,student);
displayGoodbye();
}

//@@author SebasFok
/**
* Initializes the user by attempting to load data from save files. If successful, sets the user details,
Expand All @@ -77,8 +78,10 @@ public void initialiseUser() throws IOException {

storageManager = new StorageManager();
try {
System.out.println("Attempting to retrieve data from save file... Sorry this takes a while!");
System.out.println("Attempting to look for your data file...");

showLoadingAnimation();

// Load name, major and year from studentDetails.txt file
ArrayList<String> studentDetails = storageManager.loadStudentDetails();

Expand Down Expand Up @@ -110,23 +113,11 @@ public void initialiseUser() throws IOException {

} catch (MissingFileException e) {
stopLoadingAnimation();
System.out.println("New save files will be created.");
//storage.createUserStorageFile();
//System.out.println("Files successfully created!");
//student.setSchedule(new Schedule());

System.out.println("Looks like you're new, new save files will be created.");

} catch (CorruptedFileException e) {
stopLoadingAnimation();
ui.printStorageError();
//student.setSchedule(new Schedule());
/*
try {
student.updateTimetable();
} catch (TimetableUnavailableException ignoredError) {
//should be unavailable
}
*/
}

resetStorageData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static void executePaceCommand(String[] arguments, int completedModuleCre
* It should not be null.
*/
public static void showModulesLeft(ArrayList<String> moduleCodesLeft) {
displayMessage("Modules Left: ");
displayMessage("Required Modules Left: ");
printModuleStringArray(moduleCodesLeft);
}

Expand Down
12 changes: 9 additions & 3 deletions src/main/java/seedu/duke/models/logic/Prerequisite.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ private static void flattenPrereq(
ArrayList<String> courseRequirements,
String currRequisite) throws ClassCastException {
try {

int lengthOfModulePreReqArray = modulePrereqArray.size();

// we keep a counter as if no preclusion is a module requirement for the major
Expand All @@ -171,7 +170,7 @@ private static void flattenPrereq(
if (module instanceof String) {
String formattedModule = ((String) module).split(":")[0];
formattedModule = formattedModule.replace("%", "");
if (courseRequirements.contains(formattedModule)) {
if (courseRequirements.contains(formattedModule) || currRequisite.equals("and")) {
prerequisites.add(formattedModule);
if (currRequisite.equals("or")) {
return;
Expand Down Expand Up @@ -292,7 +291,7 @@ static JSONObject getModulePrereqTree(String moduleCode) throws IOException {
*/
static boolean isModuleException(String moduleCode) {
ArrayList<String> exemptedModules = new ArrayList<>(List.of("CS1231", "CS1231S", "MA1508E", "EE4204",
"MA1511", "MA1512", "MA1521", "MA1522"));
"MA1511", "MA1512", "MA1521", "MA1522", "CS2109S"));

return exemptedModules.contains(moduleCode);
}
Expand All @@ -317,6 +316,12 @@ static ArrayList<String> getExemptedPrerequisite(String moduleCode) {
list3.add("ST2334");
map.put("EE4204", list3);

ArrayList<String> list4 = new ArrayList<>();
list4.add("CS2040S");
list4.add("CS1231S");
list4.add("MA1521");
map.put("CS2109S", list4);

ArrayList<String> emptyList = new ArrayList<>();

map.put("MA1511", emptyList);
Expand All @@ -329,6 +334,7 @@ static ArrayList<String> getExemptedPrerequisite(String moduleCode) {

map.put("MA1522", emptyList);


return map.get(moduleCode);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/models/schema/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private void addCurrentCommands() {

new Command("complete", "MODULE_CODE",
"Marks a module as complete on schedule planner."),
new Command("left", "Displays a list of remaining modules."),
new Command("left", "Displays a list of remaining required modules."),
new Command("pace", "[CURRENT_SEMESTER]", "Computes and displays your graduation pace."),

new Command("timetable", "COMMAND", "Displays a grid containing this semester's classes"),
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/duke/views/CommandLineView.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public static void displayCommands(CommandManager commandManager) {
*/
public static void showPrereq(String module,String major){
try{

System.out.println("This module's prerequisites are "
+ getModulePrereqBasedOnCourse(module.toUpperCase(),major));
}catch (InvalidPrereqException e){
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/seedu/duke/views/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void printStorageError() {
System.out.println("Unable to retrieve any data. Your save file may be corrupted.\n" +
"Please continue using the application to create new save files or overwrite " +
"the corrupted files!");
out.print("Please check ./data again");
out.println("Please check ./data again");
stopLoadingAnimation();
}

Expand All @@ -126,7 +126,7 @@ public void printStorageError() {
*
*/
public static void showLoadingAnimation() {
String[] animationChars = {"(.O_O.)","(.o_o.)","(.<_<.)","(.^_^.)"};
String[] animationChars = {"(.O_O.)","(.o_o.)","(.<_<.)","(.>_>.)","(.>_<.)","(.^_^.)"};
loadingThread = new Thread(() -> {
int i = 0;
while (!Thread.currentThread().isInterrupted()) {
Expand Down Expand Up @@ -154,6 +154,13 @@ public static void showLoadingAnimation() {
public static void stopLoadingAnimation() {
if (loadingThread != null && loadingThread.isAlive()) {
loadingThread.interrupt();
try {
// Wait for the loading thread to finish
loadingThread.join();
} catch (InterruptedException e) {
// Handle the interruption if needed
Thread.currentThread().interrupt(); // Restore interrupted status
}
}
}
}
2 changes: 1 addition & 1 deletion src/test/java/seedu/duke/controllers/LeftFeatureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void testLeftFeature_noModulesCompleted_expectMajorModuleCodes() {
.replaceAll("\r", "\n");

// Assert the printed output matches the expected value
String expectedOutput = "Modules Left: \n" +
String expectedOutput = "Required Modules Left: \n" +
"1. CG1111A 2. MA1511 3. MA1512 4. CS1010 5. GESS1000 \n" +
"6. GEC1000 7. GEN2000 8. ES2631 9. GEA1000 10. DTK1234 \n" +
"11. EG1311 12. IE2141 13. EE2211 14. EG2501 15. CDE2000 \n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void completeModule_prereqSatisfied() {

@Test
void showModulesLeftTest_arrayListModules_expectModulesLeft() {
String expectedOutput = "Modules Left: \n" +
String expectedOutput = "Required Modules Left: \n" +
"1. GEA1000 2. MA1521 3. IS1108 4. MA1522 5. CS1231S \n" +
"6. ES2660 7. CS2101 8. CS1101S 9. GESS1000 10. GEN2000";

Expand Down

0 comments on commit d636391

Please sign in to comment.