From 36faf12c2e20e6783389291b235c5916656f2d1a Mon Sep 17 00:00:00 2001 From: "Lee, Jiseop" Date: Fri, 12 Dec 2025 00:11:19 +0900 Subject: [PATCH 1/8] Add 'Editor' file and code backbone of the methods. --- src/main/java/com/unitime/feature/Editor.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/com/unitime/feature/Editor.java diff --git a/src/main/java/com/unitime/feature/Editor.java b/src/main/java/com/unitime/feature/Editor.java new file mode 100644 index 0000000..deafbc4 --- /dev/null +++ b/src/main/java/com/unitime/feature/Editor.java @@ -0,0 +1,25 @@ +package com.unitime.feature; + +public class Editor { + + private Editor (String input) { + input = input.toLowerCase(); + if (input.equals("quit")) quit(); + else if (input.equals("edit")) editList(); + else if (input.equals("next")) viewNext(); + else System.out.println("[Error] Invalid input."); + } + + public void viewNext() { + + } + + public void editList() { + + } + + public void quit() { + + } + +} From d26c683e32d9f30bbf5af9db9978fcfc89c052c2 Mon Sep 17 00:00:00 2001 From: "Lee, Jiseop" Date: Fri, 12 Dec 2025 01:09:43 +0900 Subject: [PATCH 2/8] middle save due to viewNext algorithm issue --- src/main/java/com/unitime/feature/Editor.java | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/unitime/feature/Editor.java b/src/main/java/com/unitime/feature/Editor.java index deafbc4..a1df55c 100644 --- a/src/main/java/com/unitime/feature/Editor.java +++ b/src/main/java/com/unitime/feature/Editor.java @@ -1,25 +1,63 @@ package com.unitime.feature; +import java.util.*; + +import com.unitime.UI.ResultView; +import com.unitime.algorthm.Scheduler; + public class Editor { - private Editor (String input) { + public List> schedules; + + private Editor (String input, List> schedules) { //schedules: Scheduler의 전체 시간표 리스트 넣어야 함 + this.schedules = schedules; + input = input.toLowerCase(); if (input.equals("quit")) quit(); else if (input.equals("edit")) editList(); - else if (input.equals("next")) viewNext(); + else if (input.equals("next")) viewNext(0); else System.out.println("[Error] Invalid input."); } - public void viewNext() { + public void viewNext(int i) { + ResultView rv = new ResultView(); + Scanner sc = new Scanner(System.in); + + int index = i + 5; + + String command = rv.printBatchAndGetInput(schedules, index, sc); } public void editList() { - + System.out.println("\n[Edit Mode] 과목을 수정합니다..."); + + // TODO: 기존 필수/선택 과목 리스트 가져오기 + // (어딘가에 저장되어 있어야 함 - 전역 변수 or 파일 or 반환값) + List mandatoryList = getMandatoryListFromSomewhere(); + List optionList = getOptionListFromSomewhere(); + int goalCredit = getGoalCreditFromSomewhere(); + + // 사용자에게 수정 받기 (기존 입력 클래스 활용) + CourseInputHandler.modifyCourses(mandatoryList, optionList, scanner); + + // 수정된 리스트로 Scheduler 재실행 + Scheduler scheduler = new Scheduler(); + List> newSchedules = scheduler.schedule(mandatoryList, optionList, goalCredit); + + // 처음부터 다시 출력 (currentIndex = 0) + String input = ResultView.printBatchAndGetInput(newSchedules, 0, scanner); + + // 다시 라우팅 + if (input.equals("next")) { + viewNext(newSchedules, 0, scanner); + } else if (input.equals("edit")) { + editList(newSchedules, scanner); + } } public void quit() { - + } } From 099461d8793995943721a4adcb3cb60e1c42f2df Mon Sep 17 00:00:00 2001 From: "Lee, Jiseop" Date: Fri, 12 Dec 2025 02:26:24 +0900 Subject: [PATCH 3/8] Complete 'Editor' code, and a few modifications in 'InputHandler' due to related operations and parameter passing. --- src/main/java/com/unitime/feature/Editor.java | 182 ++++++++++++++---- .../com/unitime/feature/InputHandler.java | 4 +- 2 files changed, 144 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/unitime/feature/Editor.java b/src/main/java/com/unitime/feature/Editor.java index a1df55c..4e6bfc0 100644 --- a/src/main/java/com/unitime/feature/Editor.java +++ b/src/main/java/com/unitime/feature/Editor.java @@ -1,63 +1,165 @@ package com.unitime.feature; import java.util.*; - import com.unitime.UI.ResultView; import com.unitime.algorthm.Scheduler; public class Editor { - public List> schedules; + private List> schedules; + private List mandatoryList; + private List optionList; + private int goalCredit; + + private Scanner sc; - private Editor (String input, List> schedules) { //schedules: Scheduler의 전체 시간표 리스트 넣어야 함 + // Constructor + public Editor(List> schedules, List mandatory, List optional, int credit, Scanner scanner) { this.schedules = schedules; + this.mandatoryList = mandatory; + this.optionList = optional; + this.goalCredit = credit; + this.sc = scanner; + } + + // Routing: send to function depending on its input + public void route(String input, List> currentSchedules) { + if (currentSchedules != null) { + this.schedules = currentSchedules; + } - input = input.toLowerCase(); - if (input.equals("quit")) quit(); - else if (input.equals("edit")) editList(); - else if (input.equals("next")) viewNext(0); - else System.out.println("[Error] Invalid input."); + input = input.toLowerCase().trim(); + + if (input.equals("quit")) System.quit(0); + else if (input.equals("edit")) editList(); + else if (input.equals("next")) viewLoop(5); + else { + System.out.println("[Error] Invalid input. Going back to View Mode."); + viewLoop(0); + } } - public void viewNext(int i) { - ResultView rv = new ResultView(); - Scanner sc = new Scanner(System.in); + // + private void viewLoop(int startIndex) { + int index = startIndex; + String nextInput; - int index = i + 5; - - String command = rv.printBatchAndGetInput(schedules, index, sc); + while (true) { + ResultView rv = new ResultView(); + nextInput = rv.printBatchAndGetInput(this.schedules, index, this.sc); + + if (nextInput.equals("next")) { + index += 5; + continue; + } + break; + } + route(nextInput, this.schedules); } - public void editList() { - System.out.println("\n[Edit Mode] 과목을 수정합니다..."); - - // TODO: 기존 필수/선택 과목 리스트 가져오기 - // (어딘가에 저장되어 있어야 함 - 전역 변수 or 파일 or 반환값) - List mandatoryList = getMandatoryListFromSomewhere(); - List optionList = getOptionListFromSomewhere(); - int goalCredit = getGoalCreditFromSomewhere(); - - // 사용자에게 수정 받기 (기존 입력 클래스 활용) - CourseInputHandler.modifyCourses(mandatoryList, optionList, scanner); - - // 수정된 리스트로 Scheduler 재실행 + // 'edit': edit lists and send it back to InputHandler + private void editList() { + System.out.println("[Edit Mode]"); + modifyCourse(this.mandatoryList, this.optionList); + + System.out.println("Re-calculating schedules..."); + Scheduler scheduler = new Scheduler(); - List> newSchedules = scheduler.schedule(mandatoryList, optionList, goalCredit); - - // 처음부터 다시 출력 (currentIndex = 0) - String input = ResultView.printBatchAndGetInput(newSchedules, 0, scanner); - - // 다시 라우팅 - if (input.equals("next")) { - viewNext(newSchedules, 0, scanner); - } else if (input.equals("edit")) { - editList(newSchedules, scanner); - } + this.schedules = scheduler.schedule(this.mandatoryList, this.optionList, this.goalCredit); } - public void quit() { + // helper of 'edit' + private void modifyCourse(List mandatory, List optional) { + + InputHandler ih = new InputHandler(); + + while (true) { + System.out.println("\n------------------------------------------"); + System.out.println(" Current Goal Credit: " + this.goalCredit); + System.out.println(" Mandatory: " + mandatory.size() + " courses"); + System.out.println(" Optional : " + optional.size() + " courses"); + System.out.println("------------------------------------------"); + System.out.println("1. Add/Edit MANDATORY Courses"); + System.out.println("2. Add/Edit OPTIONAL Courses"); + System.out.println("3. Remove a Course"); + System.out.println("4. Change Goal Credit"); + System.out.println("0. Finish Editing (Run Scheduler)"); + System.out.print("> Select: "); + String choice = sc.nextLine().trim(); + + // Add + if (choice.equals("1")) { + System.out.println("\n[Add to Mandatory] Type 'done' to finish."); + ih.inputLoop(sc, mandatory); + } + else if (choice.equals("2")) { + System.out.println("\n[Add to Optional] Type 'done' to finish."); + ih.inputLoop(sc, optional); + } + else if (choice.equals("3")) { + removeCourseHelper(mandatory, optional); + } + else if (choice.equals("4")) { + System.out.print("Enter new max credit: "); + try { + int newCredit = Integer.parseInt(sc.nextLine().trim()); + if (newCredit > 0) { + this.goalCredit = newCredit; + System.out.println("Goal credit updated."); + } else { + System.out.println("Credit must be positive."); + } + } catch (Exception e) { + System.out.println("Invalid number."); + } + } + else if (choice.equals("0")) { + break; + } + else { + System.out.println("Invalid choice."); + } + } } -} + // helper of 'edit': remove + private void removeCourseHelper(List mandatory, List optional) { + System.out.println("\n[Remove Course]"); + System.out.println("1. From Mandatory"); + System.out.println("2. From Optional"); + System.out.print("> Select list: "); + String listType = sc.nextLine().trim(); + + List target = null; + if (listType.equals("1")) target = mandatory; + else if (listType.equals("2")) target = optional; + else { + System.out.println("Canceled."); + return; + } + + if (target.isEmpty()) { + System.out.println("This list is empty."); + return; + } + + for (int i = 0; i < target.size(); i++) { + System.out.println("[" + i + "] " + target.get(i).getName()); + } + + System.out.print("Enter index to remove (or -1 to cancel): "); + try { + int idx = Integer.parseInt(sc.nextLine().trim()); + if (idx >= 0 && idx < target.size()) { + Course removed = target.remove(idx); + System.out.println("Removed: " + removed.getName()); + } else if (idx != -1) { + System.out.println("Invalid index."); + } + } catch (Exception e) { + System.out.println("Invalid input."); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/unitime/feature/InputHandler.java b/src/main/java/com/unitime/feature/InputHandler.java index 842bc42..0f8ffaf 100644 --- a/src/main/java/com/unitime/feature/InputHandler.java +++ b/src/main/java/com/unitime/feature/InputHandler.java @@ -68,7 +68,7 @@ public InputHandler() { } // Get user input - private void inputLoop(Scanner sc, List targetList) { + public void inputLoop(Scanner sc, List targetList) { System.out.println("------------------------------------------------------------------"); System.out.println("Format: Name / Credit / Time"); System.out.println("Example: Data Structure / 3 / Mon 12:30 14:00"); @@ -143,7 +143,7 @@ private void inputLoop(Scanner sc, List targetList) { } // Change time into minutes - private int parseMin(String t) throws Exception { + public int parseMin(String t) throws Exception { try { String[] hhmm = t.split(":"); if (hhmm.length != 2) { From e17a4ae0b3ee7df747fdd4b2b53782f315298a9f Mon Sep 17 00:00:00 2001 From: "Lee, Jiseop" Date: Fri, 12 Dec 2025 02:31:32 +0900 Subject: [PATCH 4/8] Minor change in comments --- src/main/java/com/unitime/feature/Editor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/unitime/feature/Editor.java b/src/main/java/com/unitime/feature/Editor.java index 4e6bfc0..d0be56e 100644 --- a/src/main/java/com/unitime/feature/Editor.java +++ b/src/main/java/com/unitime/feature/Editor.java @@ -39,7 +39,7 @@ public void route(String input, List> currentSchedules) { } } - // + // 'next': loop to show 5 more schedules private void viewLoop(int startIndex) { int index = startIndex; String nextInput; From b8587719c99c42c190ed0ea0e273a10e6e7c259a Mon Sep 17 00:00:00 2001 From: "Lee, Jiseop" Date: Fri, 12 Dec 2025 02:44:38 +0900 Subject: [PATCH 5/8] fix: omitted one method(quit) --- src/main/java/com/unitime/feature/Editor.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/unitime/feature/Editor.java b/src/main/java/com/unitime/feature/Editor.java index d0be56e..be8301b 100644 --- a/src/main/java/com/unitime/feature/Editor.java +++ b/src/main/java/com/unitime/feature/Editor.java @@ -162,4 +162,8 @@ private void removeCourseHelper(List mandatory, List optional) { System.out.println("Invalid input."); } } + + public void exit(){ + System.out.println("[Bye] Closing system..."); + } } \ No newline at end of file From 8ded641ff3f484ca1fe155bcba444b7827a7f4c1 Mon Sep 17 00:00:00 2001 From: "Lee, Jiseop" Date: Fri, 12 Dec 2025 02:48:50 +0900 Subject: [PATCH 6/8] fixed typo --- src/main/java/com/unitime/feature/Editor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/unitime/feature/Editor.java b/src/main/java/com/unitime/feature/Editor.java index be8301b..a61663b 100644 --- a/src/main/java/com/unitime/feature/Editor.java +++ b/src/main/java/com/unitime/feature/Editor.java @@ -30,7 +30,7 @@ public void route(String input, List> currentSchedules) { input = input.toLowerCase().trim(); - if (input.equals("quit")) System.quit(0); + if (input.equals("quit")) quit(); else if (input.equals("edit")) editList(); else if (input.equals("next")) viewLoop(5); else { @@ -163,7 +163,7 @@ private void removeCourseHelper(List mandatory, List optional) { } } - public void exit(){ + public void quit(){ System.out.println("[Bye] Closing system..."); } } \ No newline at end of file From 43407f2a30792d0cda5e78599b4b5751b4dab785 Mon Sep 17 00:00:00 2001 From: "Lee, Jiseop" Date: Fri, 12 Dec 2025 03:17:26 +0900 Subject: [PATCH 7/8] Added bound check --- src/main/java/com/unitime/feature/Editor.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/unitime/feature/Editor.java b/src/main/java/com/unitime/feature/Editor.java index a61663b..f0ae8c3 100644 --- a/src/main/java/com/unitime/feature/Editor.java +++ b/src/main/java/com/unitime/feature/Editor.java @@ -49,7 +49,11 @@ private void viewLoop(int startIndex) { nextInput = rv.printBatchAndGetInput(this.schedules, index, this.sc); if (nextInput.equals("next")) { - index += 5; + if (index + 5 < schedules.size()) { + index += 5; + } else { + System.out.println("[Info] No more schedules to show."); + } continue; } break; From 43de92998bd2a59290ea4f16930dc8058ab3545c Mon Sep 17 00:00:00 2001 From: "Lee, Jiseop" Date: Fri, 12 Dec 2025 03:19:07 +0900 Subject: [PATCH 8/8] Removed multiple sc.close() --- src/main/java/com/unitime/feature/InputHandler.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/unitime/feature/InputHandler.java b/src/main/java/com/unitime/feature/InputHandler.java index 0f8ffaf..82a71fd 100644 --- a/src/main/java/com/unitime/feature/InputHandler.java +++ b/src/main/java/com/unitime/feature/InputHandler.java @@ -63,8 +63,6 @@ public InputHandler() { System.out.println("=========================================="); System.out.println("Finding timetables..."); System.out.println("=========================================="); - - sc.close(); } // Get user input