diff --git a/src/main/java/org/example/Course.java b/src/main/java/org/example/Course.java index d990da4..10cb36b 100644 --- a/src/main/java/org/example/Course.java +++ b/src/main/java/org/example/Course.java @@ -147,12 +147,28 @@ public class Course { return courses; } + /** + * Adds a new course to the file with provided details. + * + * @param courseName The name of the course. + * @param courseCode The code of the course. + * @param courseCredit The credit value of the course. + * @param filename The name of the file to write to. + */ public static void addCourse(String courseName, String courseCode, int courseCredit, String filename) { // Write course data to the file Course course = new Course(); course.writeToFile(courseName, courseCode, courseCredit, filename); } + /** + * Checks if a course with the given name or code already exists in the file. + * + * @param filename The name of the file to read from. + * @param name The name of the course. + * @param code The code of the course. + * @return True if a course with the same name or code exists, otherwise False. + */ private static boolean courseExists(String filename, String name, String code) { List courses = readFromFile(filename); for (Course course : courses) { @@ -163,6 +179,11 @@ public class Course { return false; // No course with the same name or code found } + /** + * Adds a new course to the file based on user input. + * + * @param filename The name of the file to write to. + */ public static void addCourseFromUserInput(String filename) { Scanner scanner = new Scanner(System.in); @@ -185,6 +206,11 @@ public class Course { System.out.println("Added Course successfully!"); } + /** + * Deletes a course from the file based on user input. + * + * @param filename The name of the file to write to. + */ public static void deleteCourse(String filename) { List courses = readFromFile(filename); diff --git a/src/test/java/org/example/CourseTest.java b/src/test/java/org/example/CourseTest.java index fa987a0..ec0f7c9 100644 --- a/src/test/java/org/example/CourseTest.java +++ b/src/test/java/org/example/CourseTest.java @@ -108,6 +108,10 @@ class CourseTest { deleteTempFile(); } + /** + * Tests the addCourse method of the Course class. + * Verifies that a new course can be added to the file. + */ @Test void addCourse() { // Create a new course @@ -132,6 +136,10 @@ class CourseTest { deleteTempFile(); } + /** + * Tests the deleteCourse method of the Course class. + * Verifies that a course can be deleted from the file. + */ @Test public void testDeleteCourse() throws IOException { // Prepare test data