From d94f43320da16527440fb7d247e7625a4f417590 Mon Sep 17 00:00:00 2001 From: fdai7887 Date: Thu, 8 Feb 2024 18:34:56 +0100 Subject: [PATCH 1/4] Implemented enrollProfToCourse function in Main class --- src/main/java/org/example/Main.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index f41f76d..ed91152 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -1,4 +1,6 @@ package org.example; +import java.util.ArrayList; +import java.util.List; import java.util.Scanner; public class Main { @@ -44,6 +46,27 @@ 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); + break; case 4: // Drop Prof from Course From 5190b04a81fc96d3d39c333d01ae79092da03d75 Mon Sep 17 00:00:00 2001 From: fdai7887 Date: Thu, 8 Feb 2024 18:41:55 +0100 Subject: [PATCH 2/4] 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 From ce73746c0fc05ba8b30fc30c8a17c56cba8f1fec Mon Sep 17 00:00:00 2001 From: fdai7887 Date: Thu, 8 Feb 2024 19:11:13 +0100 Subject: [PATCH 3/4] Added dropProfFromCourse function in Main class --- src/main/java/org/example/Main.java | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index 2209447..810ca44 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -50,6 +50,46 @@ public class Main { break; case 4: // Drop Prof from 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(); + } + + Professor prof = administration.findProfessorById(profID); + List courseList = prof.getCoursesTaught(); + + System.out.println("Please enter Course ID"); + String courseID = scanner.next(); + + boolean isDeleted = false; + while(!isDeleted) { + //Checks if course exists + 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(); + + } + //Checks if Prof is enrolled in course + for (Course course : courseList) { + if (course.getCourseID().equals(courseID)) { + courseList.remove(administration.findCourseByID(courseID)); + prof.setCoursesTaught(courseList); + System.out.println("Course deleted successfully"); + isDeleted = true; + break; + } + System.out.println("The Professor is not enrolled in this course"); + System.out.println("Please enter a new Course ID"); + System.out.println("To return to main menu enter '0'"); + courseID = scanner.next(); + } + + } + break; case 5: // Drop Student from Course From ae092ecf82b92ed7f929a492ed9a883ee9a2cc04 Mon Sep 17 00:00:00 2001 From: fdai7887 Date: Thu, 8 Feb 2024 19:14:28 +0100 Subject: [PATCH 4/4] refactoring: Moved dropProfFromCourse to Administration class --- src/main/java/org/example/Administration.java | 44 +++++++++++++++++++ src/main/java/org/example/Main.java | 40 +---------------- 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index e5e4a69..fedf350 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -432,6 +432,50 @@ public class Administration { } + public void dropProfFromCourse(){ + 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(); + } + + Professor prof = this.findProfessorById(profID); + List courseList = prof.getCoursesTaught(); + + System.out.println("Please enter Course ID"); + String courseID = scanner.next(); + + boolean isDeleted = false; + while(!isDeleted) { + //Checks if course exists + 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(); + + } + //Checks if Prof is enrolled in course + for (Course course : courseList) { + if (course.getCourseID().equals(courseID)) { + courseList.remove(this.findCourseByID(courseID)); + prof.setCoursesTaught(courseList); + System.out.println("Course deleted successfully"); + isDeleted = true; + break; + } + System.out.println("The Professor is not enrolled in this course"); + System.out.println("Please enter a new Course ID"); + courseID = scanner.next(); + } + + } + + + + + } } diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index 810ca44..a5ebe9f 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -50,45 +50,7 @@ public class Main { break; case 4: // Drop Prof from 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(); - } - - Professor prof = administration.findProfessorById(profID); - List courseList = prof.getCoursesTaught(); - - System.out.println("Please enter Course ID"); - String courseID = scanner.next(); - - boolean isDeleted = false; - while(!isDeleted) { - //Checks if course exists - 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(); - - } - //Checks if Prof is enrolled in course - for (Course course : courseList) { - if (course.getCourseID().equals(courseID)) { - courseList.remove(administration.findCourseByID(courseID)); - prof.setCoursesTaught(courseList); - System.out.println("Course deleted successfully"); - isDeleted = true; - break; - } - System.out.println("The Professor is not enrolled in this course"); - System.out.println("Please enter a new Course ID"); - System.out.println("To return to main menu enter '0'"); - courseID = scanner.next(); - } - - } + administration.dropProfFromCourse(); break; case 5: