From 1765943f6b70a38b4a07d78555334b694978016a Mon Sep 17 00:00:00 2001 From: fdai7887 Date: Thu, 8 Feb 2024 14:54:55 +0100 Subject: [PATCH] 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;