From 2e315e56bf6839814217f84f1d6d044abbf47f79 Mon Sep 17 00:00:00 2001 From: fdai7600 Date: Thu, 8 Feb 2024 21:31:48 +0100 Subject: [PATCH] refactoring: encapsulates the input handling related to enrolling a student in a course --- src/main/java/org/example/Administration.java | 11 +++++++++++ src/main/java/org/example/Main.java | 6 +----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index dd214cc..07f5a16 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -509,6 +509,17 @@ public class Administration { } } + public void enrollStudentInCourseInteractive() { + System.out.println("Enter Student ID:"); + String studentId = scanner.nextLine(); // Use nextLine for consistent input handling + System.out.println("Enter Course ID:"); + String courseId = scanner.nextLine(); + + boolean enrolled = enrollStudentInCourse(studentId, courseId); +// Feedback for failure is handled within the enrollStudentInCourse method + + } + public void viewCourses() { if (courses.isEmpty()) { System.out.println("No courses available."); diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index 0bc5252..c22840f 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -40,11 +40,7 @@ public class Main { administration.registerUser(); break; case 2: // Enroll Student in Course - System.out.println("Enter Student ID:"); - String studentId = scanner.next(); - System.out.println("Enter Course ID:"); - String courseId = scanner.next(); - administration.enrollStudentInCourse(studentId, courseId); + administration.enrollStudentInCourseInteractive(); break; case 3: // Enroll Prof to Course