diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index 3613768..8d34482 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -506,6 +506,17 @@ public class Administration { } } + public void enrollStudentInCourseInteractive() { + System.out.println("Enter Student ID:"); + String studentId = scanner.nextLine(); // Use nextLine for consistent input handling + System.out.println("Enter Course ID:"); + String courseId = scanner.nextLine(); + + boolean enrolled = enrollStudentInCourse(studentId, courseId); +// Feedback for failure is handled within the enrollStudentInCourse method + + } + public void viewCourses() { if (courses.isEmpty()) { System.out.println("No courses available."); @@ -561,6 +572,18 @@ public class Administration { } + public void viewGradesFromStudent() { + System.out.print("Enter Student ID to view grades: "); + String studentId = scanner.next(); + Student student = findStudentById(studentId); + + if (student != null) { + student.printGrades(); + } else { + System.out.println("Student with ID " + studentId + " not found."); + } + } + } diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index a3b0321..4e96cb5 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -41,11 +41,7 @@ public class Main { administration.registerUser(); 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); + administration.enrollStudentInCourseInteractive(); break; case 3: // Enroll Prof to Course @@ -108,6 +104,7 @@ public class Main { break; case 10: // View Grades from Student + administration.viewGradesFromStudent(); break; case 11: diff --git a/src/main/java/org/example/Student.java b/src/main/java/org/example/Student.java index 8cfe740..a0b7074 100644 --- a/src/main/java/org/example/Student.java +++ b/src/main/java/org/example/Student.java @@ -111,6 +111,13 @@ public class Student { this.courseGrades.put(course, grade); } - + public void printGrades() { + System.out.println("Grades for Student ID: " + this.studentId + ", Name: " + this.studentName); + for (Map.Entry entry : courseGrades.entrySet()) { + Course course = entry.getKey(); + String grade = entry.getValue(); + System.out.println("Course: " + course.getCourseName() + " (" + course.getCourseID() + "), Grade: " + (grade != null ? grade : "Not graded yet")); + } + } } diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index 414404f..e77cc76 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -419,6 +419,34 @@ class AdministrationTest { assertEquals("Student",administration.findStudentById("S1010").getStudentRole()); } + + @Test + void testEnrollStudentInCourseInteractive() { + Administration administration = new Administration(); + + Student stud = sampleStudent; + administration.addStudents(stud); + Course course = sampleCourse; + administration.addCourse(course); + String studentId =stud.getStudentId(); // Use nextLine for consistent input handling + String courseId = course.getCourseID(); + + boolean enrolled = administration.enrollStudentInCourse(studentId, courseId); + + boolean correct = false; + Map courses = stud.getCourseGrades(); + + for(Course key : courses.keySet()) + { + if(key == course) + { + correct = true; + break; + } + } + + assertTrue(correct); + } @Test void dropStudentFromCourse() { Student student = sampleStudent;