From 8fc2c6d50b1e0647baa0d7ffff1af760b3578f9b Mon Sep 17 00:00:00 2001 From: fdai7600 Date: Thu, 8 Feb 2024 18:31:33 +0100 Subject: [PATCH 1/3] 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 From 3bdf705ebbcc3db139d3faaed28ffb171de6dc20 Mon Sep 17 00:00:00 2001 From: fdai7600 Date: Thu, 8 Feb 2024 18:37:05 +0100 Subject: [PATCH 2/3] Added Delete course function in Main in the new menu --- src/main/java/org/example/Main.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index f914439..49a7587 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -63,6 +63,14 @@ 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."); + } break; case 8: // View Courses From c96fbd2d52ad2b6781a01b1295c3a9d95a6ffc41 Mon Sep 17 00:00:00 2001 From: fdai7600 Date: Thu, 8 Feb 2024 18:51:07 +0100 Subject: [PATCH 3/3] Added the new Enroll Student in course --- src/main/java/org/example/Administration.java | 22 +++++++++++++++++++ src/main/java/org/example/Main.java | 9 ++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index e3fe0ee..768006d 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -1,6 +1,7 @@ package org.example; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Scanner; @@ -418,6 +419,27 @@ public class Administration { System.out.println("Course " + courseName + " (" + courseID + ") created successfully."); } } + + public boolean enrollStudentInCourse(String studentId, String courseId) { + Student student = findStudentById(studentId); + Course course = findCourseByID(courseId); + if (student != null && course != null) { + // If the course is not already enrolled + if (!student.getCourseGrades().containsKey(course)) { + student.getCourseGrades().put(course, "Not Graded"); + System.out.println("Student " + studentId + " enrolled in course " + courseId + "."); + return true; + } else { + System.out.println("Student " + studentId + " is already enrolled in course " + courseId + "."); + return false; + } + } else { + if (student == null) System.out.println("Student ID not found."); + if (course == null) System.out.println("Course ID not found."); + return false; + } + } + } diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index 49a7587..bcc2022 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -40,8 +40,13 @@ public class Main { // Register User administration.registerUser(); break; - case 2: - 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); + break; case 3: // Enroll Prof to Course break;