diff --git a/src/main/java/org/example/Course.java b/src/main/java/org/example/Course.java index 9092951..6d0ae4e 100644 --- a/src/main/java/org/example/Course.java +++ b/src/main/java/org/example/Course.java @@ -151,4 +151,14 @@ public class Course { Course course = new Course(); course.writeToFile(courseName, courseCode, courseCredit, filename); } + + private static boolean courseExists(String filename, String name, String code) { + List courses = readFromFile(filename); + for (Course course : courses) { + if (course.getCourseName().equalsIgnoreCase(name) || course.getCourseCode().equalsIgnoreCase(code)) { + return true; // Course with the same name or code already exists + } + } + return false; // No course with the same name or code found + } }