Skip to content
Closed
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
66 changes: 43 additions & 23 deletions src/main/java/com/unitime/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,69 @@

import com.unitime.UI.IntroScreen;
import com.unitime.UI.ResultView;
import com.unitime.algorthm.Scheduler;
import com.unitime.feature.InputHandler;
import com.unitime.feature.Editor;
import com.unitime.feature.Course;
import com.unitime.feature.InputHandler;
import com.unitime.algorthm.Scheduler;

public class App {
public static void main( String[] args ) {

Scanner sc = new Scanner(System.in);
IntroScreen.start();
System.out.println("Press [ENTER] to start...");
sc.nextLine();
while(true) {

InputHandler inputHandler = new InputHandler();

// 1. 인트로
IntroScreen.start(sc);

// 2. [최초 1회] InputHandler 생성
// (주의: InputHandler를 수정 안 했으니, new 하는 순간 질문들이 쏟아집니다.)
// (이게 정상입니다. 프로그램 켤 때 한 번은 물어봐야 하니까요.)
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()
);
List<Course> mandatory = inputHandler.getMandatoryList();
List<Course> optional = inputHandler.getOptionalList();
int maxCredit = inputHandler.getMaxCredit();

// 3. 알고리즘 실행
System.out.println("\n[Algorithm] Generating optimal timetables...");
Scheduler scheduler = new Scheduler();
List<List<Course>> results = scheduler.schedule(mandatory, optional, maxCredit);

// 4. 메인 루프
while(true) {

// --- View Mode ---
int currentIndex = 0;
boolean viewingResults = true;
String command = "";

while (viewingResults) {

String command = ResultView.printBatchAndGetInput(results, currentIndex, sc);
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;
}
}

// --- Edit Mode ---
if (command.equals("edit")) {
// Editor 생성
Editor editor = new Editor(mandatory, optional, maxCredit, sc);

// Editor 실행 -> (여기서 InputHandler를 안 쓰니 질문 폭탄이 안 나옴!)
editor.runEditMode();

// 업데이트된 학점 반영
maxCredit = editor.getGoalCredit();

// 스케줄러 재실행
System.out.println("\n[Update] Re-calculating schedules...");
results = scheduler.schedule(mandatory, optional, maxCredit);
}
}
}

}
}
38 changes: 14 additions & 24 deletions src/main/java/com/unitime/UI/IntroScreen.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
package com.unitime.UI;

import java.util.Scanner;

public class IntroScreen {
//set color for introscreen
// ... (색상 상수들은 그대로 두세요) ...
private static final String ANSI_RESET = "\u001b[0m";
private static final String ANSI_BOLD = "\u001b[1m";
private static final String ANSI_GREEN = "\u001b[38;5;46m";
private static final String ANSI_YELLOW = "\u001b[38;5;226m";
private static final String[] ANSI_COLORS = {
"\u001b[38;5;196m",
"\u001b[38;5;208m",
"\u001b[38;5;220m",
"\u001b[38;5;46m",
"\u001b[38;5;51m",
"\u001b[38;5;93m"
"\u001b[38;5;196m", "\u001b[38;5;208m", "\u001b[38;5;220m",
"\u001b[38;5;46m", "\u001b[38;5;51m", "\u001b[38;5;93m"
};
private static final int NUM_COLORS = ANSI_COLORS.length;
private static final int WIDTH = 80;

public static void start() {
// [수정됨] Scanner를 파라미터로 받아옵니다!
public static void start(Scanner scanner) {
printBorderedBox();

System.out.println("=".repeat(WIDTH + 4));
System.out.println(ANSI_YELLOW + " Press [ENTER] to Start UniTime_Solver." + ANSI_RESET);
System.out.println("=".repeat(WIDTH + 4));

//waiting user's enter
// [수정됨] try-catch 제거하고, 받아온 scanner로 대기
if (scanner.hasNextLine()) {
scanner.nextLine();
}
}

private static void printBorderedBox() {
// ... (이 아래 코드는 보내주신 것 그대로 두시면 됩니다!) ...
String h_border = "+-" + "-".repeat(WIDTH) + "-+";
String emptyLine = "| " + " ".repeat(WIDTH) + " |";

System.out.println(h_border);

String title = " ♬ UniTime-Solver";
int currentLength = title.length();
int padding = WIDTH - currentLength;
Expand All @@ -43,41 +45,29 @@ private static void printBorderedBox() {
String status = " Status: [ *READY to START* ]";
int statusPadding = WIDTH - status.length();


System.out.println("| " + ANSI_GREEN + status + ANSI_RESET + " ".repeat(statusPadding) + " |");
System.out.println(h_border);

String[] logo = {
" _ _ _ _____ _ ____ _ ",

" | | | |_ __ (_)_ _ (_)_ __ ___ ___ / ___| ___ | |_ ______ __ ",

" _ _ _ _____ _ ____ _ ",
" | | | |_ __ (_)_ _ (_)_ __ ___ ___ / ___| ___ | |_ ______ __ ",
" | | | | '_ \\| | | | | | '_ ` _ \\ / _ \\____\\___ \\ / _ \\| \\ \\ / /_ \\ '__|",

" | |_| | | | | | | | | | | | | | | __/_____|__) | (_) | |\\ V / __/ | ",

" \\____/|_| |_|_| |_| |_|_| |_| |_|\\___| |____/ \\___/|_| \\_/\\___|_| "
};

final int MAX_LOGO_WIDTH = 72;

System.out.println(emptyLine);

for (int i = 0; i < logo.length; i++) {
String line = logo[i];

int leftPadding = (WIDTH - MAX_LOGO_WIDTH) / 2;

System.out.print("| " + " ".repeat(leftPadding));

int printableWidth = Math.min(line.length(), MAX_LOGO_WIDTH);

for (int j = 0; j < printableWidth; j++) {
char c = line.charAt(j);

int colorIndex = (i + j) % NUM_COLORS;


System.out.print(ANSI_COLORS[colorIndex] + c + ANSI_RESET);
}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/unitime/UI/ResultView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

import com.unitime.feature.Course;

public class ResultView {
Expand Down
51 changes: 38 additions & 13 deletions src/main/java/com/unitime/feature/Course.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package com.unitime.feature;

public class Course {
private String name; // course name
private int credit; // credit

// time
private int day; // 0=Mon, 1=Tue, 2=Wed, 3=Thu, 4=Fri
public class Course implements Comparable<Course> {

private String name;
private int credit;
private int day;
private int startTime;
private int endTime;

// for toString
private String timeRaw;

public Course(String name, int credit,
int day, int startTime, int endTime, String timeRaw) {
// =======================================================
// [추가 1] 필수 과목인지 여부를 저장하는 변수
// =======================================================
private boolean isMandatory = false;


public Course(String name, int credit, int day, int startTime, int endTime, String timeRaw) {
this.name = name;
this.credit = credit;
this.day = day;
Expand All @@ -22,16 +24,39 @@ public Course(String name, int credit,
this.timeRaw = timeRaw;
}

// Getters
// ... (기존 Getters 생략) ...
public String getName() { return name; }
public int getCredit() { return credit; }
public int getDay() { return day; }
public int getStartTime() { return startTime; }
public int getEndTime() { return endTime; }


// =======================================================
// [추가 2] "이건 필수야!" 라고 설정하는 메서드 (에러 해결 핵심!)
// =======================================================
public void setMandatory(boolean isMandatory) {
this.isMandatory = isMandatory;
}

// =======================================================
// [추가 3] 필수인지 아닌지 확인하는 메서드 (ResultView에서 색깔 칠할 때 씀)
// =======================================================
public boolean isMandatory() {
return isMandatory;
}


@Override
public int compareTo(Course other) {
if (this.day != other.day) {
return Integer.compare(this.day, other.day);
}
return Integer.compare(this.startTime, other.startTime);
}

@Override
public String toString() {
return String.format("%s | %d (credits) | %s ",
name, credit, timeRaw);
return String.format("%s | %d (credits) | %s ", name, credit, timeRaw);
}
}
Loading