diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index f760a50..4b8a8db 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -43,7 +43,7 @@ public class Administration { */ public boolean deleteCourse(String courseID){ for(Course course : courses){ - if(course.getCourseCode().equals(courseID)){ + if(course.getCourseID().equals(courseID)){ courses.remove(course); return true; } @@ -59,7 +59,7 @@ public class Administration { */ public Course findCourseByID(String courseID){ for(Course course : courses){ - if(course.getCourseCode().equals(courseID)){ + if(course.getCourseID().equals(courseID)){ return course; } } diff --git a/src/main/java/org/example/Course.java b/src/main/java/org/example/Course.java index 1714e77..ae4f2fe 100644 --- a/src/main/java/org/example/Course.java +++ b/src/main/java/org/example/Course.java @@ -16,10 +16,10 @@ public class Course { private String courseName; /** The code of the course. */ - private String courseCode; + private String courseID; /** The credit value of the course. */ - private int courseCredit; + private int courseCredits; /** * Constructs a new Course object with default values. @@ -31,13 +31,13 @@ public class Course { * Constructs a new Course object with specified values. * * @param courseName The name of the course. - * @param courseCode The code of the course. - * @param courseCredit The credit value of the course. + * @param courseID The code of the course. + * @param courseCredits The credit value of the course. */ - public Course(String courseName, String courseCode, int courseCredit) { + public Course(String courseName, String courseID, int courseCredits) { this.courseName = courseName; - this.courseCode = courseCode; - this.courseCredit = courseCredit; + this.courseID = courseID; + this.courseCredits = courseCredits; } /** @@ -63,17 +63,17 @@ public class Course { * * @return The code of the course. */ - public String getCourseCode() { - return courseCode; + public String getCourseID() { + return courseID; } /** * Sets the code of the course. * - * @param courseCode The code of the course. + * @param courseID The code of the course. */ - public void setCourseCode(String courseCode) { - this.courseCode = courseCode; + public void setCourseID(String courseID) { + this.courseID = courseID; } /** @@ -81,17 +81,17 @@ public class Course { * * @return The credit value of the course. */ - public int getCourseCredit() { - return courseCredit; + public int getCourseCredits() { + return courseCredits; } /** * Sets the credit value of the course. * - * @param courseCredit The credit value of the course. + * @param courseCredits The credit value of the course. */ - public void setCourseCredit(int courseCredit) { - this.courseCredit = courseCredit; + public void setCourseCredits(int courseCredits) { + this.courseCredits = courseCredits; } /** @@ -99,8 +99,8 @@ public class Course { */ public void printCourseInfo() { System.out.println("Course Name: " + courseName); - System.out.println("Course Code: " + courseCode); - System.out.println("Course Credits: " + courseCredit); + System.out.println("Course Code: " + courseID); + System.out.println("Course Credits: " + courseCredits); } /** @@ -172,7 +172,7 @@ public class Course { 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)) { + if (course.getCourseName().equalsIgnoreCase(name) || course.getCourseID().equalsIgnoreCase(code)) { return true; // Course with the same name or code already exists } } @@ -244,8 +244,8 @@ public class Course { try (FileWriter writer = new FileWriter(filename)) { for (Course course : courses) { writer.write(course.getCourseName() + "\n"); - writer.write(course.getCourseCode() + "\n"); - writer.write(course.getCourseCredit() + "\n"); + writer.write(course.getCourseID() + "\n"); + writer.write(course.getCourseCredits() + "\n"); // Write any other fields you saved } } catch (IOException e) { diff --git a/src/test/java/org/example/CourseTest.java b/src/test/java/org/example/CourseTest.java index 704edaa..33510b6 100644 --- a/src/test/java/org/example/CourseTest.java +++ b/src/test/java/org/example/CourseTest.java @@ -63,7 +63,7 @@ class CourseTest { Course course = sampleCourse; // Write course data to the temporary file - course.writeToFile(course.getCourseName(), course.getCourseCode(), course.getCourseCredit(), TEMP_FILE); + course.writeToFile(course.getCourseName(), course.getCourseID(), course.getCourseCredits(), TEMP_FILE); // Read course data from the temporary file List courses = Course.readFromFile(TEMP_FILE); @@ -72,8 +72,8 @@ class CourseTest { assertEquals(1, courses.size()); Course readCourse = courses.get(0); assertEquals("Math", readCourse.getCourseName()); - assertEquals("M101", readCourse.getCourseCode()); - assertEquals(3, readCourse.getCourseCredit()); + assertEquals("M101", readCourse.getCourseID()); + assertEquals(3, readCourse.getCourseCredits()); // Delete the temporary file deleteTempFile(); @@ -96,13 +96,13 @@ class CourseTest { Course course1 = courses.get(0); assertEquals("Math", course1.getCourseName()); - assertEquals("C101", course1.getCourseCode()); - assertEquals(3, course1.getCourseCredit()); + assertEquals("C101", course1.getCourseID()); + assertEquals(3, course1.getCourseCredits()); Course course2 = courses.get(1); assertEquals("Science", course2.getCourseName()); - assertEquals("C201", course2.getCourseCode()); - assertEquals(4, course2.getCourseCredit()); + assertEquals("C201", course2.getCourseID()); + assertEquals(4, course2.getCourseCredits()); // Delete the temporary file deleteTempFile(); @@ -112,8 +112,8 @@ class CourseTest { void addCourse() { // Create a new course String courseName = sampleCourse.getCourseName(); - String courseCode = sampleCourse.getCourseCode(); - int courseCredit = sampleCourse.getCourseCredit(); + String courseCode = sampleCourse.getCourseID(); + int courseCredit = sampleCourse.getCourseCredits(); // Write course data to the temporary file Course.addCourse(courseName, courseCode, courseCredit, TEMP_FILE); @@ -125,8 +125,8 @@ class CourseTest { assertEquals(1, courses.size()); Course addedCourse = courses.get(0); assertEquals(courseName, addedCourse.getCourseName()); - assertEquals(courseCode, addedCourse.getCourseCode()); - assertEquals(courseCredit, addedCourse.getCourseCredit()); + assertEquals(courseCode, addedCourse.getCourseID()); + assertEquals(courseCredit, addedCourse.getCourseCredits()); // Delete the temporary file deleteTempFile(); @@ -137,14 +137,14 @@ class CourseTest { // Write courses to the test file PrintWriter writer = new PrintWriter(new FileWriter(TEMP_FILE)); writer.println(sampleCourse.getCourseName()); - writer.println(sampleCourse.getCourseCode()); - writer.println(sampleCourse.getCourseCredit()); + writer.println(sampleCourse.getCourseID()); + writer.println(sampleCourse.getCourseCredits()); writer.println(sampleCourse2.getCourseName()); - writer.println(sampleCourse2.getCourseCode()); - writer.println(sampleCourse2.getCourseCredit()); + writer.println(sampleCourse2.getCourseID()); + writer.println(sampleCourse2.getCourseCredits()); writer.println(sampleCourse3.getCourseName()); - writer.println(sampleCourse3.getCourseCode()); - writer.println(sampleCourse3.getCourseCredit()); + writer.println(sampleCourse3.getCourseID()); + writer.println(sampleCourse3.getCourseCredits()); writer.close(); // Simulate user input for course deletion