From ddeaa689cb60cc4c83e4642f626b226db52b2cd5 Mon Sep 17 00:00:00 2001 From: fdai7921 Date: Wed, 7 Feb 2024 13:25:11 +0100 Subject: [PATCH] Adding courseExists method in Course class --- src/main/java/org/example/Course.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 + } }