import models.*; import services.*; import java.util.Scanner; public class Main { private static SchoolSystem school = new SchoolSystem(); private static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { school.addCourseToSystem("Potions"); school.addCourseToSystem("Defense Against Dark Arts"); school.addCourseToSystem("Transfiguration"); runMainMenu(); } private static void runMainMenu() { while (true) { System.out.println("\n HOGWARTS SCHOOL SYSTEM "); System.out.println("1. Register (Sign Up)"); System.out.println("2. Login"); System.out.println("3. Exit"); System.out.print("\nChoose: "); int choice = getIntInput(); switch (choice) { case 1: registerMenu(); break; case 2: loginMenu(); break; case 3: System.out.println(" Goodbye!"); return; default: System.out.println(" Invalid choice!"); } } } private static void registerMenu() { System.out.println("\n══════════ REGISTER ══════════"); System.out.println("1. Register as Student"); System.out.println("2. Register as Teacher"); System.out.println("3. Back"); System.out.print("Choose: "); int choice = getIntInput(); System.out.print("Enter username: "); String username = scanner.nextLine(); String usernameError = User.validateUsername(username); if (usernameError != null) { System.out.println(" " + usernameError); return; } System.out.print("Enter password: "); String password = scanner.nextLine(); String passwordError = User.validatePassword(password); if (passwordError != null) { System.out.println(" " + passwordError); return; } boolean success; switch (choice) { case 1: success = school.registerStudent(username, password); if (success) { System.out.println(" Student registered successfully!"); } else { System.out.println(" Username already exists!"); } break; case 2: success = school.registerTeacher(username, password); if (success) { System.out.println(" Teacher registered successfully!"); } else { System.out.println(" Username already exists!"); } break; case 3: return; default: System.out.println(" Invalid choice!"); } } private static void loginMenu() { System.out.println("\n══════════ LOGIN ══════════"); System.out.println("1. Login as Student"); System.out.println("2. Login as Teacher"); System.out.println("3. Back"); System.out.print("Choose: "); int choice = getIntInput(); System.out.print("Username: "); String username = scanner.nextLine(); System.out.print("Password: "); String password = scanner.nextLine(); switch (choice) { case 1: Student student = school.loginStudent(username, password); if (student != null) { studentMenu(student); } else { System.out.println(" Invalid username or password!"); } break; case 2: Teacher teacher = school.loginTeacher(username, password); if (teacher != null) { teacherMenu(teacher); } else { System.out.println(" Invalid username or password!"); } break; case 3: return; default: System.out.println(" Invalid choice!"); } } // ==================== STUDENT MENU ==================== private static void studentMenu(Student student) { while (true) { System.out.println("\n══════════ STUDENT DASHBOARD ══════════"); System.out.println("Welcome, " + student.getUsername() + "!"); System.out.println("1. View All Available Courses"); System.out.println("2. Enroll in a Course"); System.out.println("3. View My Courses"); System.out.println("4. Logout"); System.out.print("\nChoose: "); int choice = getIntInput(); switch (choice) { case 1: System.out.print(school.getAllCoursesDisplay()); break; case 2: enrollInCourse(student); break; case 3: System.out.print(student.getMyCoursesDisplay()); break; case 4: System.out.println(" Goodbye, " + student.getUsername() + "!"); return; default: System.out.println(" Invalid choice!"); } } } private static void enrollInCourse(Student student) { System.out.print(school.getAllCoursesDisplay()); System.out.print("\nEnter Course ID to enroll: "); int courseId = getIntInput(); Course course = school.findCourseById(courseId); if (course == null) { System.out.println(" Course not found! Please enter a valid ID."); return; } if (student.enrollInCourse(course)) { System.out.println(" Successfully enrolled in " + course.getName()); } else { System.out.println(" You are already enrolled in this course!"); } } // ==================== TEACHER MENU ==================== private static void teacherMenu(Teacher teacher) { while (true) { System.out.println("\n══════════ TEACHER DASHBOARD ══════════"); System.out.println("Welcome, Professor " + teacher.getUsername() + "!"); System.out.println("1. View All Available Courses"); System.out.println("2. Add New Course to System"); System.out.println("3. View My Courses"); System.out.println("4. Add Course to My List (by ID)"); System.out.println("5. Remove Course from My List (by ID)"); System.out.println("6. View Students in My Course (by ID)"); System.out.println("7. Logout"); System.out.print("\nChoose: "); int choice = getIntInput(); switch (choice) { case 1: System.out.print(school.getAllCoursesDisplay()); break; case 2: addNewCourseToSystem(teacher); break; case 3: System.out.print(teacher.getMyCoursesDisplay()); break; case 4: addCourseToTeacher(teacher); break; case 5: removeCourseFromTeacher(teacher); break; case 6: showStudentsInTeacherCourse(teacher); break; case 7: System.out.println(" Goodbye, Professor " + teacher.getUsername() + "!"); return; default: System.out.println(" Invalid choice!"); } } } private static void addNewCourseToSystem(Teacher teacher) { System.out.print("Enter new course name: "); String courseName = scanner.nextLine(); if (school.addCourseToSystem(courseName)) { System.out.println(" Course '" + courseName + "' created successfully!"); Course newCourse = school.findCourseByName(courseName); if (newCourse != null) { teacher.addCourse(newCourse); } } else { System.out.println(" Course already exists!"); } } private static void addCourseToTeacher(Teacher teacher) { System.out.print(school.getAllCoursesDisplay()); System.out.print("\nEnter Course ID to add to your list: "); int courseId = getIntInput(); Course course = school.findCourseById(courseId); if (course == null) { System.out.println(" Course not found!"); return; } if (teacher.addCourse(course)) { System.out.println(" Course '" + course.getName() + "' added to your list!"); } else { System.out.println(" You already teach this course!"); } } private static void removeCourseFromTeacher(Teacher teacher) { System.out.print(teacher.getMyCoursesDisplay()); if (teacher.getMyCourses().isEmpty()) return; System.out.print("\nEnter Course ID to remove from your list: "); int courseId = getIntInput(); Course course = school.findCourseById(courseId); if (course == null) { System.out.println(" Course not found!"); return; } if (teacher.removeCourse(course)) { System.out.println(" Course '" + course.getName() + "' removed from your list!"); } else { System.out.println(" You don't teach this course!"); } } private static void showStudentsInTeacherCourse(Teacher teacher) { System.out.print(teacher.getMyCoursesDisplay()); if (teacher.getMyCourses().isEmpty()) return; System.out.print("\nEnter Course ID to see students: "); int courseId = getIntInput(); Course course = school.findCourseById(courseId); if (course == null) { System.out.println(" Course not found!"); return; } String result = teacher.getStudentsDisplayForCourse(course); System.out.println(result); } private static int getIntInput() { try { int value = scanner.nextInt(); scanner.nextLine(); return value; } catch (Exception e) { scanner.nextLine(); return -1; } } }