Browse Source

refactoring: encapsulates the input handling related to enrolling a student in a course

remotes/origin/fdai7780
fdai7600 11 months ago
parent
commit
2e315e56bf
  1. 11
      src/main/java/org/example/Administration.java
  2. 6
      src/main/java/org/example/Main.java

11
src/main/java/org/example/Administration.java

@ -509,6 +509,17 @@ public class Administration {
} }
} }
public void enrollStudentInCourseInteractive() {
System.out.println("Enter Student ID:");
String studentId = scanner.nextLine(); // Use nextLine for consistent input handling
System.out.println("Enter Course ID:");
String courseId = scanner.nextLine();
boolean enrolled = enrollStudentInCourse(studentId, courseId);
// Feedback for failure is handled within the enrollStudentInCourse method
}
public void viewCourses() { public void viewCourses() {
if (courses.isEmpty()) { if (courses.isEmpty()) {
System.out.println("No courses available."); System.out.println("No courses available.");

6
src/main/java/org/example/Main.java

@ -40,11 +40,7 @@ public class Main {
administration.registerUser(); administration.registerUser();
break; break;
case 2: // Enroll Student in Course case 2: // Enroll Student in Course
System.out.println("Enter Student ID:");
String studentId = scanner.next();
System.out.println("Enter Course ID:");
String courseId = scanner.next();
administration.enrollStudentInCourse(studentId, courseId);
administration.enrollStudentInCourseInteractive();
break; break;
case 3: case 3:
// Enroll Prof to Course // Enroll Prof to Course

Loading…
Cancel
Save