From d8f09ce6a2120dd31a342a820c5f60d6d4bdcd18 Mon Sep 17 00:00:00 2001 From: fdai7600 Date: Thu, 8 Feb 2024 23:18:52 +0100 Subject: [PATCH 1/2] refactoring: improving the readability of the input --- src/main/java/org/example/Administration.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index d1baaa4..434e445 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -507,9 +507,9 @@ public class Administration { } public void enrollStudentInCourseInteractive() { - System.out.println("Enter Student ID:"); + System.out.print("Enter Student ID:"); String studentId = scanner.nextLine(); // Use nextLine for consistent input handling - System.out.println("Enter Course ID:"); + System.out.print("Enter Course ID:"); String courseId = scanner.nextLine(); boolean enrolled = enrollStudentInCourse(studentId, courseId); From a12205e796794d2648436f2012128bf546dd03fb Mon Sep 17 00:00:00 2001 From: fdai7600 Date: Thu, 8 Feb 2024 23:22:00 +0100 Subject: [PATCH 2/2] Test: added testAssignGrade --- src/test/java/org/example/StudentTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/org/example/StudentTest.java b/src/test/java/org/example/StudentTest.java index d9e6410..6e2abaf 100644 --- a/src/test/java/org/example/StudentTest.java +++ b/src/test/java/org/example/StudentTest.java @@ -87,6 +87,25 @@ class StudentTest { } + @Test + void testAssignGrade() { + + Student student = new Student("John Doe", "S1001", "Student"); + Course course = new Course("Introduction to Java", "C101", 3); // Assuming your Course class has a constructor that accepts name, ID, and credits + // Pre-assignment check: Ensure the course is not already graded + assertNull(student.getCourseGrades().get(course), "Course should not have a grade assigned before test."); + + // Assign a grade to the course + String grade = "A"; + student.assignGrade(course, grade); + // Post-assignment check: Ensure the grade is correctly assigned + assertEquals(grade, student.getCourseGrades().get(course), "Grade assigned to course does not match expected grade."); + + // Optional: Test changing the grade + String newGrade = "B"; + student.assignGrade(course, newGrade); + assertEquals(newGrade, student.getCourseGrades().get(course), "Grade update for course does not match expected new grade."); + } } \ No newline at end of file