diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index 57b3e6d..e613922 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; @@ -540,6 +541,38 @@ public class Administration { return false; } + + 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."); + } + } + + 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 2154de4..2544299 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -40,9 +40,14 @@ public class Main { switch (choice) { case 1: // Register User + administration.registerUser(); break; - case 2: - // Enroll Student in Course + 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 @@ -58,9 +63,24 @@ 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 + 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: administration.viewCourses();