From 110c8d0ded301d152cfcfe6f1e9b73fa6d3b5756 Mon Sep 17 00:00:00 2001 From: fdai7600 Date: Thu, 8 Feb 2024 22:55:53 +0100 Subject: [PATCH] refactoring: encapsulated the input handling related with case 7 --- src/main/java/org/example/Administration.java | 10 ++++++++++ src/main/java/org/example/Main.java | 9 +-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index d6851e3..180e9c0 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -586,6 +586,16 @@ public class Administration { System.out.println("Student with ID " + studentId + " not found."); } } + public void deleteCourseWithInput(Scanner scanner) { + System.out.print("Enter the Course ID of the course you wish to delete: "); + String courseIDToDelete = scanner.next(); + boolean isDeleted = deleteCourse(courseIDToDelete); + if (isDeleted) { + System.out.println("Course with ID " + courseIDToDelete + " has been successfully deleted."); + } else { + System.out.println("Course with ID " + courseIDToDelete + " not found."); + } + } } diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index ef9fa77..2b338ac 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -74,14 +74,7 @@ public class Main { break; case 7: // Delete Course - System.out.println("Enter the Course ID of the course you wish to delete:"); - String courseIDToDelete = scanner.next(); - boolean isDeleted = administration.deleteCourse(courseIDToDelete); - if (isDeleted) { - System.out.println("Course with ID " + courseIDToDelete + " has been successfully deleted."); - } else { - System.out.println("Course with ID " + courseIDToDelete + " not found."); - } + administration.deleteCourseWithInput(scanner); break; case 8: administration.viewCourses();