|
|
@ -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<Course> 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<Course> courses = readFromFile(filename); |
|
|
|
|
|
|
|