diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index cae9eb6..5e7f8e1 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -1,9 +1,6 @@ package org.example; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Scanner; +import java.util.*; public class Administration { /** @@ -509,6 +506,38 @@ public class Administration { } + + 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; + } + + public void viewCourses() { + if (courses.isEmpty()) { + System.out.println("No courses available."); + } else { + System.out.println("Available Courses:"); + for (Course course : courses) { + course.printCourseInfo(); + } + } + } + } diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index bbc5851..aa3cdb0 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -30,10 +30,7 @@ public class Main { System.out.println("8. View Courses"); System.out.println("9. Assign Grade to Student"); System.out.println("10. View Grades from Student"); - System.out.println("11. View User"); - System.out.println("12. Delete User"); - System.out.println("13. View Course List"); - System.out.println("14. Exit (includes saving data in the files)"); + System.out.println("11. Exit (includes saving data in the files)"); System.out.print("Select an option: "); int choice = scanner.nextInt(); @@ -84,23 +81,38 @@ public class Main { break; case 8: // View Courses + administration.viewCourses(); break; 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 + System.out.print("Enter Student ID to view grades: "); + String GradedstudentId = scanner.next(); + Student student = administration.findStudentById(GradedstudentId); + if (student != null) { + student.printGrades(); + } else { + System.out.println("Student not found."); + } break; + case 11: - // View User - break; - case 12: - // Delete User - break; - case 13: - // View Course List - break; - case 14: // Exit (includes saving data in the files) exit = true; System.out.println("Exiting..."); diff --git a/src/main/java/org/example/Student.java b/src/main/java/org/example/Student.java index fd76b0d..2d510ff 100644 --- a/src/main/java/org/example/Student.java +++ b/src/main/java/org/example/Student.java @@ -107,6 +107,16 @@ public class Student { return students; } + public void assignGrade(Course course, String grade) { + // Assuming courseGrades is a Map where the course is the key and the grade is the value + this.courseGrades.put(course, grade); + } + public void printGrades() { + System.out.println("Grades for Student ID: " + this.studentId); + for (Map.Entry entry : courseGrades.entrySet()) { + System.out.println("Course: " + entry.getKey().getCourseName() + ", Grade: " + entry.getValue()); + } + } }