diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index bbd7f83..470ca9f 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -407,6 +407,70 @@ 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."); + } + } + + 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; + } + } + + public void viewCourses() { + if (courses.isEmpty()) { + System.out.println("No courses available."); + } else { + System.out.println("Available Courses:"); + for (Course course : courses) { + course.printCourseInfo(); + } + } + } + + + public boolean assignGradeToStudent(String studentId, String courseId, String grade) { + Student student = findStudentById(studentId); + // First, find the course by ID to ensure it exists in the system. + Course course = findCourseByID(courseId); + + if (student != null && course != null) { + // Check if the student is enrolled in the specified course. + if (student.getCourseGrades().containsKey(course)) { + // Student is enrolled in the course, proceed to assign the grade. + student.getCourseGrades().put(course, grade); + return true; + } else { + // Student is not enrolled in the specified course. + System.out.println("Student is not enrolled in the specified course."); + return false; + } + } + return false; + } + } diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index f41f76d..1566a84 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -58,10 +58,23 @@ public class Main { // Delete Course break; case 8: - // View Courses + administration.viewCourses(); break; - case 9: + case 9:{ // Assign Grade to Student + System.out.println("Assign Grade to Student selected"); + System.out.print("Enter Student ID: "); + String toBeGradedStudentId = scanner.next(); + System.out.print("Enter Course ID: "); + String toBeGradedCourseId = scanner.next(); + System.out.print("Enter Grade: "); + String grade = scanner.next(); + boolean success = administration.assignGradeToStudent(toBeGradedStudentId, toBeGradedCourseId, grade); + if (success) { + System.out.println("Grade assigned successfully."); + } else { + System.out.println("Failed to assign grade. Ensure the student and course IDs are correct."); + }} break; case 10: // View Grades from Student diff --git a/src/main/java/org/example/Student.java b/src/main/java/org/example/Student.java index fd76b0d..8cfe740 100644 --- a/src/main/java/org/example/Student.java +++ b/src/main/java/org/example/Student.java @@ -107,6 +107,10 @@ public class Student { return students; } + public void assignGrade(Course course, String grade) { + this.courseGrades.put(course, grade); + } + }