From 5190b04a81fc96d3d39c333d01ae79092da03d75 Mon Sep 17 00:00:00 2001 From: fdai7887 Date: Thu, 8 Feb 2024 18:41:55 +0100 Subject: [PATCH] refactoring: Moved enrollProfInCourse function to Administration --- src/main/java/org/example/Administration.java | 25 +++++++++++++++++++ src/main/java/org/example/Main.java | 22 +--------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index bbd7f83..e5e4a69 100644 --- a/src/main/java/org/example/Administration.java +++ b/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 courseList = prof.getCoursesTaught(); + courseList.add(course); + prof.setCoursesTaught(courseList); + System.out.println("Professor enrolled successfully"); + + } + } diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index ed91152..2209447 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -46,27 +46,7 @@ public class Main { break; case 3: // 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 courseList = prof.getCoursesTaught(); - courseList.add(course); - prof.setCoursesTaught(courseList); - + administration.enrollProfInCourse(); break; case 4: // Drop Prof from Course