From b0fea42a7c170e838e205970163bdb4b56e51112 Mon Sep 17 00:00:00 2001 From: fdai7600 Date: Thu, 8 Feb 2024 23:00:12 +0100 Subject: [PATCH 1/2] refactoring: encapsulated the input handling related with case 6 --- src/main/java/org/example/Administration.java | 12 ++++++++++++ src/main/java/org/example/Main.java | 8 +------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index 180e9c0..4970258 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -597,6 +597,18 @@ public class Administration { } } + public void createCourseWithInput(Scanner scanner) { + System.out.print("Enter Course Name: "); + String courseName = scanner.next(); + System.out.print("Enter Course ID: "); + String courseID = scanner.next(); + System.out.print("Enter Credits: "); + int credits = scanner.nextInt(); + Course newCourse = new Course(courseName, courseID, credits); + addCourse(newCourse); + System.out.println("Course created successfully."); + } + } diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index 2b338ac..47a62e1 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -64,13 +64,7 @@ public class Main { break; case 6: // Create Course - System.out.println("Enter Course Name:"); - String courseName = scanner.next(); - System.out.println("Enter Course ID:"); - String courseID = scanner.next(); - System.out.println("Enter Credits:"); - int credits = scanner.nextInt(); - administration.createCourse(courseName, courseID, credits); + administration.createCourseWithInput(scanner); break; case 7: // Delete Course From a3dd0f5764ce47e82304d37bbb65cfc6edef8d3d Mon Sep 17 00:00:00 2001 From: fdai7600 Date: Thu, 8 Feb 2024 23:12:08 +0100 Subject: [PATCH 2/2] refactoring: encapsulated the input handling related with case 5 --- src/main/java/org/example/Administration.java | 8 ++++++++ src/main/java/org/example/Main.java | 9 +-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index 4970258..d1baaa4 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -609,6 +609,14 @@ public class Administration { System.out.println("Course created successfully."); } + public void dropStudentFromCourseWithInput(Scanner scanner) { + System.out.println("Enter Student ID:"); + String studentID = scanner.next(); + System.out.println("Enter Course ID:"); + String courseID = scanner.next(); + dropStudentFromCourse(studentID, courseID); + } + } diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index 47a62e1..f8296ce 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -50,17 +50,10 @@ public class Main { case 4: // Drop Prof from Course administration.dropProfFromCourse(); - break; case 5: // Drop Student from Course - System.out.println("Enter Student ID"); - String studentID = scanner.next(); - System.out.println("Enter Course ID"); - String courseIdToDrop = scanner.next(); - - administration.dropStudentFromCourse(studentID, courseIdToDrop); - + administration.dropStudentFromCourseWithInput(scanner); break; case 6: // Create Course