diff --git a/src/main/java/com/unitime/App.java b/src/main/java/com/unitime/App.java index b423ab9..387a3cf 100644 --- a/src/main/java/com/unitime/App.java +++ b/src/main/java/com/unitime/App.java @@ -2,52 +2,45 @@ import java.util.List; import java.util.Scanner; - import com.unitime.UI.IntroScreen; -import com.unitime.UI.ResultView; import com.unitime.algorthm.Scheduler; import com.unitime.feature.Course; -import com.unitime.feature.InputHandler; +import com.unitime.feature.Editor; +import com.unitime.feature.InputHandler; public class App { - public static void main( String[] args ) { + public static void main(String[] args) { + // Only one scanner!!!!! Scanner sc = new Scanner(System.in); + IntroScreen.start(); System.out.println("Press [ENTER] to start..."); sc.nextLine(); - while(true) { - - InputHandler inputHandler = new InputHandler(); - - System.out.println("\n[Algorithm] Generating optimal timetables..."); - Scheduler scheduler = new Scheduler(); - List> results = scheduler.schedule( - inputHandler.getMandatoryList(), - inputHandler.getOptionalList(), - inputHandler.getMaxCredit() - ); - - int currentIndex = 0; - boolean viewingResults = true; - - while (viewingResults) { - String command = ResultView.printBatchAndGetInput(results, currentIndex, sc); - - if (command.equals("next")) { - - if (currentIndex + 5 < results.size()) { - currentIndex += 5; - } else { - - } - } - else if (command.equals("edit")) { - viewingResults = false; - } - } - } - } + // get input + InputHandler inputHandler = new InputHandler(); + inputHandler.handle(sc); + + // First result + System.out.println("\n[Algorithm] Generating optimal timetables..."); + Scheduler scheduler = new Scheduler(); + List> results = scheduler.schedule( + inputHandler.getMandatoryList(), + inputHandler.getOptionalList(), + inputHandler.getMaxCredit() + ); + + // Editor is in charge of all post-operations (next,quit,edit) + Editor editor = new Editor( + results, + inputHandler.getMandatoryList(), + inputHandler.getOptionalList(), + inputHandler.getMaxCredit(), + sc + ); + editor.start(); -} + sc.close(); + } +} \ No newline at end of file diff --git a/src/main/java/com/unitime/UI/ResultView.java b/src/main/java/com/unitime/UI/ResultView.java index 699d397..8d389af 100644 --- a/src/main/java/com/unitime/UI/ResultView.java +++ b/src/main/java/com/unitime/UI/ResultView.java @@ -63,7 +63,7 @@ public static String printBatchAndGetInput(List> allSchedules, int String input = scanner.nextLine().trim().toLowerCase(); //Edit: return only 'next' or 'edit' - if (input.equals("next") || input.equals("edit")) { + if (input.equals("next") || input.equals("edit") || input.equals("quit")) { return input; } @@ -114,7 +114,7 @@ private static void printNavigationMenu(boolean hasNext) { System.out.println(CYAN + "\n-------------------------------------------------------------" + RESET); if (hasNext) { - System.out.println(" ( > ω < ) Select: [" + BLUE + "next" + RESET + "] or [" + RED + "edit" + RESET + "] "); + System.out.println(" ( > ω < ) Select: [" + BLUE + "next" + RESET + "] or [" + RED + "edit" + RESET + "] or [" + YELLOW + "quit" + RESET + "] "); System.out.println(" Type '" + BLUE + "next" + RESET + "' to see more timetables."); } else { System.out.println(" ( > ω < ) Select: [" + RED + "edit" + RESET + "] "); @@ -122,6 +122,7 @@ private static void printNavigationMenu(boolean hasNext) { } System.out.println(" Type '" + RED + "edit" + RESET + "' to modify your courses."); + System.out.println(" Type '" + YELLOW + "quit" + RESET + "' to close UniTime-Solver."); System.out.println(CYAN + "-------------------------------------------------------------" + RESET); } diff --git a/src/main/java/com/unitime/feature/Editor.java b/src/main/java/com/unitime/feature/Editor.java index f0ae8c3..837dcf0 100644 --- a/src/main/java/com/unitime/feature/Editor.java +++ b/src/main/java/com/unitime/feature/Editor.java @@ -22,6 +22,10 @@ public Editor(List> schedules, List mandatory, List this.sc = scanner; } + public void start() { + viewLoop(0); + } + // Routing: send to function depending on its input public void route(String input, List> currentSchedules) { if (currentSchedules != null) { @@ -48,18 +52,19 @@ private void viewLoop(int startIndex) { ResultView rv = new ResultView(); nextInput = rv.printBatchAndGetInput(this.schedules, index, this.sc); - if (nextInput.equals("next")) { - if (index + 5 < schedules.size()) { - index += 5; - } else { - System.out.println("[Info] No more schedules to show."); - } - continue; + if(nextInput.equals("quit")) { + quit(); + break; + } + + int nextIndex = startIndex; + if(nextInput.equals("next")) { + if (startIndex + 5 < schedules.size()) nextIndex += 5; + else System.out.println("[Info] Last page."); } - break; - } - route(nextInput, this.schedules); + route(nextInput, this.schedules); + } } // 'edit': edit lists and send it back to InputHandler @@ -71,6 +76,9 @@ private void editList() { Scheduler scheduler = new Scheduler(); this.schedules = scheduler.schedule(this.mandatoryList, this.optionList, this.goalCredit); + + System.out.println("Calculation Done. Showing results..."); + viewLoop(0); } // helper of 'edit' @@ -169,5 +177,6 @@ private void removeCourseHelper(List mandatory, List optional) { public void quit(){ System.out.println("[Bye] Closing system..."); + System.exit(0); } } \ 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 82a71fd..fe2af10 100644 --- a/src/main/java/com/unitime/feature/InputHandler.java +++ b/src/main/java/com/unitime/feature/InputHandler.java @@ -10,9 +10,7 @@ public class InputHandler { private List optionalList = new ArrayList<>(); private int maxCredit = 0; - public InputHandler() { - Scanner sc = new Scanner(System.in); - + public void handle(Scanner sc) { System.out.println("===== UniTime-Solver: Input Courses ====="); // Maximum credit @@ -36,11 +34,16 @@ public InputHandler() { System.out.println("\n[1] Enter MANDATORY Courses"); inputLoop(sc, mandatoryList); - // OptionalList에 담기 + // OptionalList System.out.println("\n[2] Enter OPTIONAL Courses"); inputLoop(sc, optionalList); - // Show result + printSummary(); + } + + + // Show result + public void printSummary() { System.out.println("\n=========================================="); System.out.println(" Check Input Summary "); System.out.println("==========================================");