Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 30 additions & 37 deletions src/main/java/com/unitime/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<Course>> 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<List<Course>> 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();
}
}
5 changes: 3 additions & 2 deletions src/main/java/com/unitime/UI/ResultView.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static String printBatchAndGetInput(List<List<Course>> 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;
}

Expand Down Expand Up @@ -114,14 +114,15 @@ 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 + "] ");
System.out.println(" " + YELLOW + "(End of List)" + RESET + " No more timetables.");
}

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);
}

Expand Down
29 changes: 19 additions & 10 deletions src/main/java/com/unitime/feature/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public Editor(List<List<Course>> schedules, List<Course> mandatory, List<Course>
this.sc = scanner;
}

public void start() {
viewLoop(0);
}

// Routing: send to function depending on its input
public void route(String input, List<List<Course>> currentSchedules) {
if (currentSchedules != null) {
Expand All @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -169,5 +177,6 @@ private void removeCourseHelper(List<Course> mandatory, List<Course> optional) {

public void quit(){
System.out.println("[Bye] Closing system...");
System.exit(0);
}
}
13 changes: 8 additions & 5 deletions src/main/java/com/unitime/feature/InputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ public class InputHandler {
private List<Course> 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
Expand All @@ -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("==========================================");
Expand Down