From 8fc2c6d50b1e0647baa0d7ffff1af760b3578f9b Mon Sep 17 00:00:00 2001 From: fdai7600 Date: Thu, 8 Feb 2024 18:31:33 +0100 Subject: [PATCH] Added Create course function Administration and implemented in Main --- src/main/java/org/example/Administration.java | 11 +++++++++++ src/main/java/org/example/Main.java | 11 +++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index bbd7f83..e3fe0ee 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -407,6 +407,17 @@ public class Administration { } + + public void createCourse(String courseName, String courseID, int credits) { + // Check if a course with the given ID already exists + if (findCourseByID(courseID) != null) { + System.out.println("A course with ID " + courseID + " already exists."); + } else { + Course newCourse = new Course(courseName, courseID, credits); + courses.add(newCourse); + System.out.println("Course " + courseName + " (" + courseID + ") created successfully."); + } + } } diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index f41f76d..f914439 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -38,10 +38,10 @@ public class Main { switch (choice) { case 1: // Register User + administration.registerUser(); break; case 2: - // Enroll Student in Course - break; + break; case 3: // Enroll Prof to Course break; @@ -53,6 +53,13 @@ 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); break; case 7: // Delete Course