Browse Source

Adding courseExists method in Course class

remotes/origin/fdai7780
fdai7921 11 months ago
parent
commit
ddeaa689cb
  1. 10
      src/main/java/org/example/Course.java

10
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<Course> 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
}
}
Loading…
Cancel
Save