From 1765943f6b70a38b4a07d78555334b694978016a Mon Sep 17 00:00:00 2001 From: fdai7887 Date: Thu, 8 Feb 2024 14:54:55 +0100 Subject: [PATCH 1/3] refactoring: moving initializeDummyData to Administration class --- src/main/java/org/example/Administration.java | 19 +++++++++++++ src/main/java/org/example/Main.java | 28 ++++--------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index 4b8a8db..e9ac3ea 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -359,6 +359,25 @@ public class Administration { } return false; } + public void initializeDummyData(){ + Student student1 = new Student("Mark", "S1001", "Student"); + Student student2 = new Student("Gustavo", "S1002", "Student"); + this.addStudents(student1); + this.addStudents(student2); + Professor prof1 = new Professor("Joachim", "P1001", "Professor"); + Professor prof2 = new Professor("Herbert", "P1002", "Professor"); + this.addProfessor(prof1); + this.addProfessor(prof2); + Admin admin1 = new Admin ("Peter", "A1001", "Admin"); + Admin admin2 = new Admin ("Martin", "A1002", "Admin"); + this.addAdmin(admin1); + this.addAdmin(admin2); + Course course1 = new Course("MathDUMMY", "CDUMMY1", 5); + Course course2 = new Course("EnglishDUMMY", "CDUMMY2", 6); + this.addCourse(course1); + this.addCourse(course2); + + } } diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index f796f26..e7a9a57 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -48,32 +48,16 @@ public class Main { break; case 7: - System.out.println("Dummy data initialized."); - - Student student1 = new Student("Mark", "S1001", "Student"); - Student student2 = new Student("Sebastian", "S1002", "Student"); - administration.addStudents(student1); - administration.addStudents(student2); - Professor prof1 = new Professor("Joachim", "P1001", "Professor"); - Professor prof2 = new Professor("Herbert", "P1002", "Professor"); - administration.addProfessor(prof1); - administration.addProfessor(prof2); - Admin admin1 = new Admin ("Peter", "A1001", "Admin"); - Admin admin2 = new Admin ("Martin", "A1002", "Admin"); - administration.addAdmin(admin1); - administration.addAdmin(admin2); - Course.addCourse("Math", "C1001", 5, "courseData.txt"); - Course.addCourse("English", "C1002", 6, "courseData.txt"); - - DummyDataExists = true; + if(!DummyDataExists){ + administration.initializeDummyData(); + System.out.println("Dummy data initialized."); + } + else{System.out.println("Dummy Data could already exists");} break; case 8: - if (DummyDataExists){ - Course.deleteCourse("courseData.txt"); - Course.deleteCourse("courseData.txt"); - } + exit = true; System.out.println("Exiting..."); break; From 5f422da0793a49e92f50d92f4e31714d936c065d Mon Sep 17 00:00:00 2001 From: fdai7887 Date: Thu, 8 Feb 2024 15:49:48 +0100 Subject: [PATCH 2/3] Added getters and setters in Administration class --- src/main/java/org/example/Administration.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/main/java/org/example/Administration.java b/src/main/java/org/example/Administration.java index e9ac3ea..e3edbfb 100644 --- a/src/main/java/org/example/Administration.java +++ b/src/main/java/org/example/Administration.java @@ -14,6 +14,38 @@ public class Administration { private List courses; Scanner scanner = new Scanner(System.in); + public List getProfessors() { + return professors; + } + + public void setProfessors(List professors) { + this.professors = professors; + } + + public List getAdmins() { + return admins; + } + + public void setAdmins(List admins) { + this.admins = admins; + } + + public List getStudents() { + return students; + } + + public void setStudents(List students) { + this.students = students; + } + + public List getCourses() { + return courses; + } + + public void setCourses(List courses) { + this.courses = courses; + } + /** * Constructor */ From ec254257f3675072eda248d943cf7331df2b668a Mon Sep 17 00:00:00 2001 From: fdai7887 Date: Thu, 8 Feb 2024 15:51:23 +0100 Subject: [PATCH 3/3] Added test for initializeDummyData in AdministrationTest class --- .../java/org/example/AdministrationTest.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/example/AdministrationTest.java b/src/test/java/org/example/AdministrationTest.java index 6f24b85..1dc593f 100644 --- a/src/test/java/org/example/AdministrationTest.java +++ b/src/test/java/org/example/AdministrationTest.java @@ -287,4 +287,22 @@ class AdministrationTest { // Finding the added course assertEquals(course, admin.findCourseByID("M101")); } -} \ No newline at end of file + @Test + public void testInitializeDummyData(){ + admin.initializeDummyData(); + + // Check if students are initialized correctly + assertEquals(2, admin.getStudents().size()); + + // Check if professors are initialized correctly + assertEquals(2, admin.getProfessors().size()); + + // Check if admins are initialized correctly + assertEquals(2, admin.getAdmins().size()); + + // Check if courses are initialized correctly + assertEquals(2, admin.getCourses().size()); + } + + + }