Browse Source

refactoring: Moved enrollProfInCourse function to Administration

remotes/origin/fdai7780
fdai7887 11 months ago
parent
commit
5190b04a81
  1. 25
      src/main/java/org/example/Administration.java
  2. 22
      src/main/java/org/example/Main.java

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

@ -407,6 +407,31 @@ public class Administration {
} }
public void enrollProfInCourse(){
System.out.println("Please enter Professor ID");
String profID = scanner.next();
while(this.findProfessorById(profID) == null){
System.out.println("This Professor does not exist");
System.out.println("Please enter a new Professor ID");
profID = scanner.next();
}
System.out.println("Please enter Course ID");
String courseID = scanner.next();
while(this.findCourseByID(courseID) == null){
System.out.println("This Course does not exist");
System.out.println("Please enter a new Course ID");
courseID = scanner.next();
}
Professor prof = this.findProfessorById(profID);
Course course = this.findCourseByID(courseID);
List<Course> courseList = prof.getCoursesTaught();
courseList.add(course);
prof.setCoursesTaught(courseList);
System.out.println("Professor enrolled successfully");
}
} }

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

@ -46,27 +46,7 @@ public class Main {
break; break;
case 3: case 3:
// Enroll Prof to Course // Enroll Prof to Course
System.out.println("Please enter Professor ID");
String profID = scanner.next();
while(administration.findProfessorById(profID) == null){
System.out.println("This Professor does not exist");
System.out.println("Please enter a new Professor ID");
profID = scanner.next();
}
System.out.println("Please enter Course ID");
String courseID = scanner.next();
while(administration.findCourseByID(courseID) == null){
System.out.println("This Course does not exist");
System.out.println("Please enter a new Course ID");
courseID = scanner.next();
}
Professor prof = administration.findProfessorById(profID);
Course course = administration.findCourseByID(courseID);
List<Course> courseList = prof.getCoursesTaught();
courseList.add(course);
prof.setCoursesTaught(courseList);
administration.enrollProfInCourse();
break; break;
case 4: case 4:
// Drop Prof from Course // Drop Prof from Course

Loading…
Cancel
Save