diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..278b59f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+# Default ignored files
+/shelf/
+/.idea/workspace.xml
+
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..919ce1f
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..a55e7a1
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..a1757ae
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..de4b033
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..a48a3b3
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24,_22_21_[Changes]/shelved.patch b/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24,_22_21_[Changes]/shelved.patch
new file mode 100644
index 0000000..d0336b9
--- /dev/null
+++ b/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24,_22_21_[Changes]/shelved.patch
@@ -0,0 +1,56 @@
+Index: src/main/java/Commands.java
+IDEA additional info:
+Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
+<+>import java.util.HashMap;\nimport java.util.Map;\n\npublic class Commands {\n private Map courseList = new HashMap<>();\n private Map studentList = new HashMap<>();\n private Map teacherList = new HashMap<>();\n\n\n public Commands(Map courseList, Map studentList, Map teacherList) {\n setCourseList(courseList);\n setStudentList(studentList);\n setTeacherList(teacherList);\n }\n\n public Map getCourseList() {\n return courseList;\n }\n\n public void setCourseList(Map courseList) {\n this.courseList = courseList;\n }\n\n public Map getStudentList() {\n return studentList;\n }\n\n public void setStudentList(Map studentList) {\n this.studentList = studentList;\n }\n\n public Map getTeacherList() {\n return teacherList;\n }\n\n public void setTeacherList(Map teacherList) {\n this.teacherList = teacherList;\n }\n\n public void commandSelector(CommandEnum commandAction){\n String studentID = \"asdfasdf\";\n String courseID = \"asdfasdf\";\n String teacherID = \"asdfasdf\";\n switch (commandAction){\n case ENROLL:\n\n enroll(studentID,courseID);\n break;\n case ASSIGN:\n assign(teacherID,courseID);\n break;\n case SHOW_COURSES:\n ShowCourses();\n break;\n case LOOKUP_COURSE:\n LookupCourse(courseID);\n break;\n case SHOW_STUDENTS:\n ShowStudents();\n break;\n case LOOKUP_STUDENT:\n LookupStudent(studentID);\n break;\n case SHOW_TEACHERS:\n ShowTeachers();\n break;\n case LOOKUP_TEACHER:\n LookupTeacher(teacherID);\n break;\n case SHOW_PROFIT:\n ShowProfit();\n break;\n default:\n System.err.println(\"The command selected is not available\");\n break;\n }\n }\n\n public void enroll(String studentID, String courseID){ // This command will help enroll the student specified in the corresponding course. While also updating the money_earned of that course based on its price\n }\n\n public void assign(String teacherID,String courseID){ //This command will help assign the teacher specified to the corresponding course\n\n }\n\n public void ShowCourses(){ //This command will display a list of all courses\n\n }\n\n public void LookupCourse(String courseID){ // This command will display the full details of the specified course\n\n }\n\n public void ShowStudents(){ //This command will display a list of all students\n\n }\n\n public void LookupStudent(String studentID){ //This command will display the full details of the specified student\n\n }\n\n public void ShowTeachers(){ //This command will display a list of all teachers\n\n }\n\n public void LookupTeacher(String teacherID){ // This command will display the full details of the specified teacher\n\n }\n\n public void ShowProfit(){ //This command will calculate (The total money earned from all courses) - (The sum of all the teachers' salaries) and return the result\n\n }\n}\n\n
+Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
+<+>UTF-8
+===================================================================
+diff --git a/src/main/java/Commands.java b/src/main/java/Commands.java
+--- a/src/main/java/Commands.java
++++ b/src/main/java/Commands.java
+@@ -41,35 +41,44 @@
+ String studentID = "asdfasdf";
+ String courseID = "asdfasdf";
+ String teacherID = "asdfasdf";
++
+ switch (commandAction){
+ case ENROLL:
+-
+ enroll(studentID,courseID);
+ break;
++
+ case ASSIGN:
+ assign(teacherID,courseID);
+ break;
++
+ case SHOW_COURSES:
+ ShowCourses();
+ break;
++
+ case LOOKUP_COURSE:
+ LookupCourse(courseID);
+ break;
++
+ case SHOW_STUDENTS:
+ ShowStudents();
+ break;
++
+ case LOOKUP_STUDENT:
+ LookupStudent(studentID);
+ break;
++
+ case SHOW_TEACHERS:
+ ShowTeachers();
+ break;
++
+ case LOOKUP_TEACHER:
+ LookupTeacher(teacherID);
+ break;
++
+ case SHOW_PROFIT:
+ ShowProfit();
+ break;
++
+ default:
+ System.err.println("The command selected is not available");
+ break;
diff --git a/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24,_22_21_[Changes]1/shelved.patch b/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24,_22_21_[Changes]1/shelved.patch
new file mode 100644
index 0000000..68ddf05
--- /dev/null
+++ b/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24,_22_21_[Changes]1/shelved.patch
@@ -0,0 +1,17 @@
+Index: .idea/.gitignore
+IDEA additional info:
+Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
+<+># Default ignored files\n/shelf/\n/workspace.xml\n
+Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
+<+>UTF-8
+===================================================================
+diff --git a/.idea/.gitignore b/.idea/.gitignore
+--- a/.idea/.gitignore
++++ b/.idea/.gitignore
+@@ -1,3 +1,6 @@
+ # Default ignored files
+ /shelf/
+ /workspace.xml
++/jarRepositories.xml
++/compiler.xml
++/encodings.xml
diff --git a/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24,_22_22_[Changes]/shelved.patch b/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24,_22_22_[Changes]/shelved.patch
new file mode 100644
index 0000000..5c602be
--- /dev/null
+++ b/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24,_22_22_[Changes]/shelved.patch
@@ -0,0 +1,20 @@
+Index: .idea/.gitignore
+IDEA additional info:
+Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
+<+># Default ignored files\n/shelf/\n/workspace.xml\n/misc.xml\n/vcs.xml\n/homework-java-ironschool.iml\n\n\n\n
+Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
+<+>UTF-8
+===================================================================
+diff --git a/.idea/.gitignore b/.idea/.gitignore
+--- a/.idea/.gitignore (revision 878ef3ff79760b86937e8a4f8753d19bad0f7e45)
++++ b/.idea/.gitignore (date 1710192118606)
+@@ -1,6 +1,9 @@
+ # Default ignored files
+ /shelf/
+ /workspace.xml
++/jarRepositories.xml
++/compiler.xml
++/encodings.xml
+ /misc.xml
+ /vcs.xml
+ /homework-java-ironschool.iml
diff --git a/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24,_22_29_[Changes]/shelved.patch b/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24,_22_29_[Changes]/shelved.patch
new file mode 100644
index 0000000..84a018d
--- /dev/null
+++ b/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24,_22_29_[Changes]/shelved.patch
@@ -0,0 +1,60 @@
+Index: .idea/.gitignore
+IDEA additional info:
+Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
+<+># Default ignored files\n/shelf/\n/workspace.xml\n
+Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
+<+>UTF-8
+===================================================================
+diff --git a/.idea/.gitignore b/.idea/.gitignore
+--- a/.idea/.gitignore (revision ad4b7edd47241cca602d690cade7aefa428eba3a)
++++ b/.idea/.gitignore (date 1710192181630)
+@@ -1,3 +1,12 @@
+ # Default ignored files
+ /shelf/
+ /workspace.xml
++/jarRepositories.xml
++/compiler.xml
++/encodings.xml
++/misc.xml
++/vcs.xml
++/homework-java-ironschool.iml
++
++
++
+Index: src/main/java/Course.java
+IDEA additional info:
+Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
+<+>\nimport java.util.HashMap;\nimport java.util.UUID;\npublic class Course {\n private String courseId;\n private String name;\n\n\n private double price;\n private double money_earned;\n private Teacher teacher;\n private HashMap courseList = new HashMap();\n\n\n public Course(String courseId, String name, double price, double money_earned) {\n setCourseId(courseId);\n setName(name);\n setPrice(price);\n }\n\n public String getCourseId() {\n return UUID.randomUUID().toString();\n }\n\n public void setCourseId(String courseId) {\n this.courseId = courseId;\n }\n\n public String getName() {\n return name;\n }\n\n public void setName(String name) {\n this.name = name;\n }\n\n public double getPrice() {\n return price;\n }\n\n public void setPrice(double price) {\n this.price = price;\n }\n\n public double getMoney_earned() {\n return money_earned;\n }\n\n public void setMoney_earned(double money_earned) {\n this.money_earned = money_earned;\n }\n\n public Teacher getTeacher() {\n return teacher;\n }\n\n public void setTeacher(Teacher teacher) {\n this.teacher = teacher;\n }\n\n public void courseEnroll(Student student, Course x){\n courseList.put(student.getStudentId(), x);\n }\n}\n
+Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
+<+>UTF-8
+===================================================================
+diff --git a/src/main/java/Course.java b/src/main/java/Course.java
+--- a/src/main/java/Course.java (revision ad4b7edd47241cca602d690cade7aefa428eba3a)
++++ b/src/main/java/Course.java (date 1710192506278)
+@@ -1,5 +1,7 @@
+
++import java.util.ArrayList;
+ import java.util.HashMap;
++import java.util.List;
+ import java.util.UUID;
+ public class Course {
+ private String courseId;
+@@ -9,7 +11,7 @@
+ private double price;
+ private double money_earned;
+ private Teacher teacher;
+- private HashMap courseList = new HashMap();
++ private List studentList = new ArrayList<>();
+
+
+ public Course(String courseId, String name, double price, double money_earned) {
+@@ -58,7 +60,7 @@
+ this.teacher = teacher;
+ }
+
+- public void courseEnroll(Student student, Course x){
+- courseList.put(student.getStudentId(), x);
++ public void courseEnroll(Student student){
++ studentList.add(student);
+ }
+ }
diff --git a/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24__22_21__Changes_.xml b/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24__22_21__Changes_.xml
new file mode 100644
index 0000000..475614f
--- /dev/null
+++ b/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24__22_21__Changes_.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24__22_21__Changes_1.xml b/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24__22_21__Changes_1.xml
new file mode 100644
index 0000000..3c04b6e
--- /dev/null
+++ b/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24__22_21__Changes_1.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24__22_22__Changes_.xml b/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24__22_22__Changes_.xml
new file mode 100644
index 0000000..2afb38d
--- /dev/null
+++ b/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24__22_22__Changes_.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24__22_29__Changes_.xml b/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24__22_29__Changes_.xml
new file mode 100644
index 0000000..1cba5e1
--- /dev/null
+++ b/.idea/shelf/Uncommitted_changes_before_Checkout_at_11_3_24__22_29__Changes_.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..bb4cf1e
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,31 @@
+
+
+ 4.0.0
+
+ groupId
+ homework-java-ironschool
+ 1.0-SNAPSHOT
+
+
+ 21
+ 21
+ UTF-8
+
+
+
+
+ org.junit.jupiter
+ junit-jupiter
+ 5.9.1
+ test
+
+
+ org.projectlombok
+ lombok
+ 1.18.30
+ provided
+
+
+
\ No newline at end of file
diff --git a/src/main/java/Application.java b/src/main/java/Application.java
new file mode 100644
index 0000000..e2c1314
--- /dev/null
+++ b/src/main/java/Application.java
@@ -0,0 +1,273 @@
+import lombok.Data;
+import lombok.Getter;
+
+import java.util.*;
+
+@Data
+public class Application {
+ private Map courseList = new HashMap<>();
+ private Map studentList = new HashMap<>();
+ private Map teacherList = new HashMap<>();
+ private final Scanner scanner = new Scanner(System.in);
+
+ public Application() {
+
+ }
+
+ public void SetUp(){
+ createSchoolName();
+ setTeacherList(teacherDetails());
+ setStudentList(studentDetails());
+ setCourseList(courseDetails());
+ }
+
+ public Map getCourseList() {
+ return courseList;
+ }
+
+ public void setCourseList(Map courseList) {
+ this.courseList = courseList;
+ }
+
+ public Map getStudentList() {
+ return studentList;
+ }
+
+ public void setStudentList(Map studentList) {
+ this.studentList = studentList;
+ }
+
+ public Map getTeacherList() {
+ return teacherList;
+ }
+
+ public void setTeacherList(Map teacherList) {
+ this.teacherList = teacherList;
+ }
+
+ public void run() {
+ String response = " ";
+ Commands commands = new Commands(this.getCourseList(), this.getStudentList(), this.getTeacherList());
+ Selector(commands);
+ }
+
+ public void createSchoolName() {
+ System.out.println("Welcome to the School Application");
+ while (true) {
+ try {
+ System.out.print("Please enter the name of the school:");
+
+ String schoolName = scanner.nextLine();
+ if (schoolName.isBlank()) {
+ throw new IllegalArgumentException( "\u001B[31mSchool name cannot be blank.\u001B[0m");
+ }
+
+ System.out.println("Your school is: " + schoolName);
+ break;
+ } catch (Exception e) {
+ System.out.println("\u001B[31mAn error occurred: " + e.getMessage());
+ }
+ }
+ }
+
+ public int numberOfComponents(SchoolComponents schoolComponents) {
+ int number;
+
+ do {
+ System.out.println(String.format("How many %s are there in the school: ", schoolComponents));
+ while (!scanner.hasNextInt()) {
+ System.err.println(String.format("Please enter a valid number for the %s ", schoolComponents));
+ scanner.next();
+ }
+
+ number = scanner.nextInt();
+
+ if (number <= 0) {
+ System.err.println(String.format("The number of %s can't be 0 or negative", schoolComponents));
+ } else if (number == 1) {
+ System.out.println(String.format("In your school there is only " + number + " %s", schoolComponents));
+ } else {
+ System.out.println(String.format("In your school there are " + number + " %s", schoolComponents));
+ }
+
+ } while (number <= 0);
+
+ return number;
+
+ }
+
+ public Map teacherDetails() {
+ Map teachersMap = new HashMap<>();
+ int number = numberOfComponents(SchoolComponents.TEACHERS);
+ scanner.nextLine();
+ for (int i = 0; i < number; i++) {
+ System.out.println("Enter details for Teacher " + (i + 1) + ":");
+ String name = validateInput("Name", "Name cannot be empty", "Name cannot contain numbers");
+ double salary = validateDoubleInput("Salary", "Invalid input for salary. Please enter a valid number");
+
+ Teacher teacher = new Teacher(name, salary);
+ teachersMap.put(teacher.getTeacherId(), teacher);
+ }
+
+ for (Map.Entry entry : teachersMap.entrySet()) {
+ System.out.println("Teacher ID: " + entry.getKey() + ", Name: " + entry.getValue().getName() + ", Salary: " + entry.getValue().getSalary() +" Euros");
+ }
+
+ return teachersMap;
+
+ }
+
+ public Map studentDetails() {
+ Map studentMap = new HashMap<>();
+ int number = numberOfComponents(SchoolComponents.STUDENTS);
+ scanner.nextLine();
+ for (int i = 0; i < number; i++) {
+ System.out.println("Enter details for Student " + (i + 1) + ":");
+ String name = validateInput("Name", "Name cannot be empty", "Name cannot contain numbers");
+ String address = validateInput("Address", "Address cannot be empty", "Address is not valid");
+ String email = validateInput("Email", "Email cannot be empty", "Email is not valid");
+
+ Student student = new Student(name, address, email);
+ studentMap.put(student.getStudentId(), student);
+ }
+ for (Map.Entry entry : studentMap.entrySet()) {
+ System.out.println("Student ID: " + entry.getKey() + ", Name: " + entry.getValue().getName() + ", Address: " + entry.getValue().getAddress() + ", Email: " + entry.getValue().getEmail());
+ }
+ return studentMap;
+ }
+
+
+
+ public Map courseDetails() {
+ Map coursesMap = new HashMap<>();
+ int number = numberOfComponents(SchoolComponents.COURSES);
+ scanner.nextLine();
+ for (int i = 0; i < number; i++) {
+ System.out.println("Enter details for Course " + (i + 1) + ":");
+ String name = validateInput("Course Name", "Course Name cannot be empty", "Name cannot contain numbers");
+ double price = validateDoubleInput("Price", "Invalid input for price. Please enter a valid number");
+
+ Course course = new Course(name, price);
+ coursesMap.put(course.getCourseId(), course);
+ }
+
+ for (Map.Entry entry : coursesMap.entrySet()) {
+ System.out.println("Course ID: " + entry.getKey() + ", Name: " + entry.getValue().getName() + ", Price: " + entry.getValue().getPrice() + " Euros.");
+ }
+
+ return coursesMap;
+
+ }
+
+ public void Selector(Commands comandos){
+ while(true) {
+ Scanner scanner = new Scanner(System.in);
+ System.out.println(("Do you want to use a command? (y/n)"));
+ String response = scanner.next();
+ scanner.nextLine();
+ if (response.equals("y")) {
+ System.out.println("Choose a command:\n");
+ System.out.println("1. Enroll\n");
+ System.out.println("2. Assign\n");
+ System.out.println("3. Show courses\n");
+ System.out.println("4. Lookup course\n");
+ System.out.println("5. Show students\n");
+ System.out.println("6. Lookup student\n");
+ System.out.println("7. Show teachers\n");
+ System.out.println("8. Lookup teacher\n");
+ System.out.println("9. Show profit\n");
+ System.out.println("10. Show course enrolled students\n");
+ try {
+ int commandoption = scanner.nextInt();
+ switch (commandoption) {
+ case 1:
+ comandos.commandSelector(CommandEnum.ENROLL);
+ break;
+ case 2:
+ comandos.commandSelector(CommandEnum.ASSIGN);
+ break;
+ case 3:
+ comandos.commandSelector(CommandEnum.SHOW_COURSES);
+ break;
+ case 4:
+ comandos.commandSelector(CommandEnum.LOOKUP_COURSE);
+ break;
+ case 5:
+ comandos.commandSelector(CommandEnum.SHOW_STUDENTS);
+ break;
+ case 6:
+ comandos.commandSelector(CommandEnum.LOOKUP_STUDENT);
+ break;
+ case 7:
+ comandos.commandSelector(CommandEnum.SHOW_TEACHERS);
+ break;
+ case 8:
+ comandos.commandSelector(CommandEnum.LOOKUP_TEACHER);
+ break;
+ case 9:
+ comandos.commandSelector(CommandEnum.SHOW_PROFIT);
+ break;
+ case 10:
+ comandos.commandSelector(CommandEnum.SHOW_COURSE_STUDENTS);
+ break;
+ default:
+ System.err.println("The option selected is not available");
+ break;
+ }
+ } catch (InputMismatchException ime) {
+ System.err.println("The option selected is not available");
+ }
+ } else if (response.equals("n")) {
+ return;
+ } else {
+ System.err.println("You typed a non-valid option");
+ }
+ }
+ }
+
+ public String validateInput(String fieldName, String emptyErrorMessage, String invalidErrorMessage) {
+ String input = "";
+ while (true) {
+ try {
+ System.out.print(fieldName + ": ");
+ input = scanner.nextLine();
+ if (input.isBlank()) {
+ throw new IllegalArgumentException("\u001B[31m" + emptyErrorMessage + "\u001B[0m");
+ } else if (fieldName.equals("Name") && input.matches(".*\\d+.*")) {
+ throw new IllegalArgumentException("\u001B[31m" + invalidErrorMessage + "\u001B[0m");
+ } else if (fieldName.equals("Email") && !input.contains("@")) {
+ throw new IllegalArgumentException("\u001B[31m" + invalidErrorMessage + "\u001B[0m");
+ }
+ return input;
+ } catch (IllegalArgumentException e) {
+ System.out.println("\u001B[31mError: " + e.getMessage() + "\u001B[0m");
+ }
+ }
+ }
+
+ public double validateDoubleInput(String fieldName, String errorMessage) {
+ double input = 0;
+ boolean validInput = false;
+ while (!validInput) {
+ System.out.print(fieldName + ": ");
+ try {
+ input = Double.parseDouble(scanner.nextLine());
+ validInput = true;
+ if (input < 0) {
+ validInput = false;
+ System.out.println("\u001B[31m" + errorMessage + "\u001B[0m");
+ }
+ } catch (NumberFormatException e) {
+ System.out.println("\u001B[31m" + errorMessage + "\u001B[0m");
+ }
+ }
+ return input;
+ }
+
+
+
+}
+
+
+
+
diff --git a/src/main/java/CommandEnum.java b/src/main/java/CommandEnum.java
new file mode 100644
index 0000000..8191981
--- /dev/null
+++ b/src/main/java/CommandEnum.java
@@ -0,0 +1,12 @@
+public enum CommandEnum {
+ ENROLL,
+ ASSIGN,
+ SHOW_COURSES,
+ LOOKUP_COURSE,
+ SHOW_STUDENTS,
+ LOOKUP_STUDENT,
+ SHOW_TEACHERS,
+ LOOKUP_TEACHER,
+ SHOW_PROFIT,
+ SHOW_COURSE_STUDENTS
+}
diff --git a/src/main/java/Commands.java b/src/main/java/Commands.java
new file mode 100644
index 0000000..7563da5
--- /dev/null
+++ b/src/main/java/Commands.java
@@ -0,0 +1,323 @@
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.*;
+
+@Setter
+@Getter
+public class Commands{
+ private Map courseList = new LinkedHashMap<>();
+ private Map studentList = new LinkedHashMap<>();
+ private Map teacherList = new LinkedHashMap<>();
+
+
+ public Commands(Map courseList, Map studentList, Map teacherList) {
+ setCourseList(courseList);
+ setStudentList(studentList);
+ setTeacherList(teacherList);
+ }
+
+ public Map getCourseList() {
+ return courseList;
+ }
+
+ public void setCourseList(Map courseList) {
+ this.courseList = courseList;
+ }
+
+ public Map getStudentList() {
+ return studentList;
+ }
+
+ public void setStudentList(Map studentList) {
+ this.studentList = studentList;
+ }
+
+ public Map getTeacherList() {
+ return teacherList;
+ }
+
+ public void setTeacherList(Map teacherList) {
+ this.teacherList = teacherList;
+ }
+
+ public void commandSelector(CommandEnum commandAction){
+ String studentID = "";
+ String courseID = "";
+ String teacherID = "";
+ Boolean validOption = false;
+ Scanner scanner = new Scanner(System.in);
+
+ switch (commandAction){
+ case ENROLL:
+ do {
+ System.out.println("Which course do you want to enroll? (write the id):\n");
+ courseList.forEach((key, value) -> {
+ System.out.println(key + " = " + value.getName() + " ");
+ });
+ try {
+ courseID = scanner.next();
+ if (courseList.containsKey(courseID)) {
+ validOption = true;
+ }else{
+ System.err.println("The course introduced does not exist");
+ }
+ }catch(IllegalArgumentException iae){
+ System.err.println("The option introduced is not correct");
+ }
+ }while(validOption == false);
+ validOption = false;
+ do {
+ System.out.println("Which student do you want to enroll in this course? (write the id):\n");
+ studentList.forEach((key, value) -> {
+ System.out.println(key + " = " + value.getName() + " ");
+ });
+ try {
+ studentID = scanner.next();
+ if (studentList.containsKey(studentID)) {
+ enroll(studentID, courseID);
+ validOption = true;
+ }else{
+ System.err.println("The student introduced does not exist");
+ }
+ } catch (IllegalArgumentException iae) {
+ System.err.println("The option introduced is not correct");
+ }
+ }while(validOption == false);
+ break;
+ case ASSIGN:
+ do {
+ System.out.println("In which course do you want to assign a teacher? (write the id):\n");
+ courseList.forEach((key,value) -> {
+ System.out.println(key + " = " + value.getName() + " ");
+ });
+ try{
+ courseID = scanner.next();
+ if(courseList.containsKey(courseID)){
+ validOption = true;
+ }else{
+ System.err.println("The course introduced does not exist");
+ }
+ }catch(IllegalArgumentException iae){
+ System.err.println("The option introduced is not correct");
+ }
+ }while(validOption == false);
+ validOption = false;
+ do{
+ System.out.println("Which teacher do you want to assign to this course? (write the id):\n");
+ teacherList.forEach((key,value) -> {
+ System.out.println(key + " = " + value.getName()+ " ");
+ });
+ try {
+ teacherID = scanner.next();
+ if(teacherList.containsKey(teacherID)){
+ assign(teacherID, courseID);
+ validOption = true;
+ }else{
+ System.err.println("The teacher introduced does not exist");
+ }
+ }catch(IllegalArgumentException iae){
+ System.err.println("The option introduced is not correct");
+ }
+ }while(validOption == false);
+ break;
+ case SHOW_COURSES:
+ ShowCourses();
+ break;
+ case LOOKUP_COURSE:
+ do{
+ System.out.println("Which course do you want to look up? (write the id):\n");
+ courseList.forEach((key,value) -> {
+ System.out.println(key + " = " + value.getName() + " ");
+ });
+ try{
+ courseID = scanner.next();
+ if(courseList.containsKey(courseID)){
+ LookupCourse(courseID);
+ validOption = true;
+ }else{
+ System.err.println("The course introduced does not exist");
+ }
+ }catch(IllegalArgumentException iae){
+ System.err.println("The option introduced is not correct");
+ }
+ }while(validOption == false);
+ break;
+ case SHOW_STUDENTS:
+ ShowStudents();
+ break;
+ case LOOKUP_STUDENT:
+ do{
+ System.out.println("Which student do you want to look up? (write the id):\n");
+ studentList.forEach((key,value) -> {
+ System.out.println(key + " = " + value.getName() + " ");
+ });
+ try{
+ studentID = scanner.next();
+ if(studentList.containsKey(studentID)){
+ LookupStudent(studentID);
+ validOption = true;
+ }else{
+ System.err.println("The student introduced does not exist");
+ }
+ }catch(IllegalArgumentException iae){
+ System.err.println("The option introduced is not correct");
+ }
+ }while(validOption == false);
+ break;
+ case SHOW_TEACHERS:
+ ShowTeachers();
+ break;
+ case LOOKUP_TEACHER:
+ do{
+ System.out.println("Which teacher do you want to look up? (write the id):\n");
+ teacherList.forEach((key,value) -> {
+ System.out.println(key + " = " + value.getName() + " ");
+ });
+ try{
+ teacherID = scanner.next();
+ if(teacherList.containsKey(teacherID)){
+ LookupTeacher(teacherID);
+ validOption = true;
+ }else{
+ System.err.println("The teacher introduced does not exist");
+ }
+ }catch(IllegalArgumentException iae){
+ System.err.println("The option introduced is not correct");
+ }
+ }while(validOption == false);
+ break;
+ case SHOW_PROFIT:
+ ShowProfit();
+ break;
+ case SHOW_COURSE_STUDENTS:
+ do{
+ System.out.println("Which course do you want to look up? (write the id):\n");
+ courseList.forEach((key,value) -> {
+ System.out.println(key + " = " + value.getName() + " ");
+ });
+ try{
+ courseID = scanner.next();
+ if(courseList.containsKey(courseID)){
+ ShowCourseStudents(courseID);
+ validOption = true;
+ }else{
+ System.err.println("The course introduced does not exist");
+ }
+ }catch(IllegalArgumentException iae){
+ System.err.println("The option introduced is not correct");
+ }
+ } while(!validOption);
+ break;
+ default:
+ System.err.println("The command selected is not available");
+ break;
+ }
+ }
+
+ public void enroll(String studentID, String courseID) {
+ Student student = studentList.get(studentID);
+ Course course = courseList.get(courseID);
+ course.courseEnroll(student);
+ student.setCourse(course);
+
+ // Increase money earned
+ course.setMoney_earned(course.getMoney_earned() + course.getPrice());
+ }
+
+ public void assign(String teacherID, String courseID){ //This command will help assign the teacher specified to the corresponding course
+ Teacher teacher = teacherList.get(teacherID);
+ Course course = courseList.get(courseID);
+
+ course.setTeacher(teacher);
+ }
+
+ public void ShowCourses(){ //This command will display a list of all courses
+
+ System.out.println("List of Courses: ");
+ for (Map.Entry entry : courseList.entrySet()) {
+ System.out.println(entry.getKey() + " : " + entry.getValue().getName());
+ }
+ }
+
+ public void LookupCourse(String courseID) { // This command will display the full details of the specified course
+
+ if (courseList.containsKey(courseID)) {
+ System.out.println("Course ID: " + courseID);
+ System.out.println("Course Name: " + courseList.get(courseID).getName());
+ System.out.println("Course Price: " + courseList.get(courseID).getPrice());
+ System.out.println("Course Money Earned: " + courseList.get(courseID).getMoney_earned());
+ if (courseList.get(courseID).getTeacher() == null) {
+ System.out.println("Course Teacher: " + "No teacher assigned");
+ } else {
+ System.out.println("Course Teacher: " + courseList.get(courseID).getTeacher().getName()); }
+ }
+ }
+ public void ShowStudents(){ //This command will display a list of all students
+
+ System.out.println("List of Students: ");
+ for (Map.Entry entry : studentList.entrySet()) {
+ System.out.println(entry.getKey() + " : " + entry.getValue().getName());
+ }
+ }
+
+ public void LookupStudent(String studentID){ //This command will display the full details of the specified student
+
+ if(studentList.containsKey(studentID)){
+ System.out.println("Student ID: " + studentID);
+ System.out.println("Student Name: " + studentList.get(studentID).getName());
+ System.out.println("Student Address: " + studentList.get(studentID).getAddress());
+ System.out.println("Student Email: " + studentList.get(studentID).getEmail());
+ if (studentList.get(studentID).getCourse() == null) {
+ System.out.println("Student Course: " + "No course enrolled");
+ }else{
+ System.out.println("Student Course: " + studentList.get(studentID).getCourse().getName());}
+ }
+ }
+
+ public void ShowTeachers(){ //This command will display a list of all teachers
+
+ System.out.println("List of Teachers: ");
+ for (Map.Entry entry : teacherList.entrySet()) {
+ System.out.println(entry.getKey() + " : " + entry.getValue().getName());
+ }
+ }
+
+ public void LookupTeacher(String teacherID){ // This command will display the full details of the specified teacher
+
+ if(teacherList.containsKey(teacherID)){
+ System.out.println("Teacher ID: " + teacherID);
+ System.out.println("Teacher Name: " + teacherList.get(teacherID).getName());
+ System.out.println("Teacher Salary: " + teacherList.get(teacherID).getSalary());
+ }
+ }
+
+ public void ShowProfit(){ //This command will calculate (The total money earned from all courses) - (The sum of all the teachers' salaries) and return the result
+ if (courseList.isEmpty())
+ return ;
+
+ double profit = 0;
+ for (Course oneCourse : courseList.values()) {
+ profit += oneCourse.getMoney_earned();
+ if (oneCourse.getTeacher() != null)
+ profit -= oneCourse.getTeacher().getSalary();
+ }
+
+ System.out.println("Total profit: " + profit + "€");
+ }
+
+ public void ShowCourseStudents(String courseID){ //This command will list the students enrolled in the given course
+ Course course = courseList.get(courseID);
+ List students = course.getStudents();
+
+ if (students.isEmpty()) {
+ System.out.println(course.getName() + " has no students enrolled");
+ return ;
+ }
+ System.out.println(course.getName() + " students:");
+ for (Student student : students) {
+ System.out.println(student.getStudentId() + ": " + student.getName());
+ }
+ }
+}
+
diff --git a/src/main/java/Course.java b/src/main/java/Course.java
new file mode 100644
index 0000000..5f06cd7
--- /dev/null
+++ b/src/main/java/Course.java
@@ -0,0 +1,78 @@
+
+import lombok.Getter;
+import lombok.NonNull;
+import lombok.Setter;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+@Getter
+@Setter
+public class Course {
+ private String courseId;
+ private String name;
+
+ private double price;
+ private double money_earned;
+ private Teacher teacher;
+ private List students = new ArrayList<>();
+
+
+ public Course(String name, double price) {
+ setCourseId(UUID.randomUUID().toString());
+ setName(name);
+ setPrice(price);
+ }
+
+ public String getCourseId() {
+ return courseId;
+ }
+
+ public void setCourseId(@NonNull String courseId) {
+ this.courseId = courseId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(@NonNull String name) {
+ this.name = name;
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(@NonNull double price) {
+ this.price = price;
+ }
+
+ public double getMoney_earned() {
+ return money_earned;
+ }
+
+ public void setMoney_earned(double money_earned) {
+ this.money_earned = money_earned;
+ }
+
+ public Teacher getTeacher() {
+ return teacher;
+ }
+
+ public void setTeacher(Teacher teacher) {
+ this.teacher = teacher;
+ }
+
+ public List getStudents() {
+ return students;
+ }
+
+ public void setStudents(List students) {
+ this.students = students;
+ }
+
+ public void courseEnroll(Student student){
+ students.add(student);
+ }
+}
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
new file mode 100644
index 0000000..25a847f
--- /dev/null
+++ b/src/main/java/Main.java
@@ -0,0 +1,7 @@
+public class Main {
+ public static void main(String[] args) {
+ Application application = new Application();
+ application.SetUp();
+ application.run();
+ }
+}
diff --git a/src/main/java/SchoolComponents.java b/src/main/java/SchoolComponents.java
new file mode 100644
index 0000000..6cdf958
--- /dev/null
+++ b/src/main/java/SchoolComponents.java
@@ -0,0 +1,19 @@
+public enum SchoolComponents {
+
+ TEACHERS ("teachers"),
+ STUDENTS ("students"),
+ COURSES ("courses");
+
+ private final String label;
+
+ SchoolComponents(String label) {
+ this.label = label;
+ }
+
+ @Override
+ public String toString() {
+ return label;
+ }
+
+
+}
diff --git a/src/main/java/Student.java b/src/main/java/Student.java
new file mode 100644
index 0000000..5a64817
--- /dev/null
+++ b/src/main/java/Student.java
@@ -0,0 +1,52 @@
+import java.util.UUID;
+
+public class Student {
+ private final String studentId;
+ private String name;
+ private String address;
+ private String email;
+ private Course course;
+
+ public Student(String name, String address, String email) {
+ this.studentId = UUID.randomUUID().toString();
+ this.name = name;
+ this.address = address;
+ this.email = email;
+ }
+
+ public String getStudentId() {
+ return studentId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public Course getCourse() {
+ return course;
+ }
+
+ public void setCourse(Course course) {
+ this.course = course;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/Teacher.java b/src/main/java/Teacher.java
new file mode 100644
index 0000000..b45ec11
--- /dev/null
+++ b/src/main/java/Teacher.java
@@ -0,0 +1,40 @@
+import java.util.UUID;
+
+
+public class Teacher {
+ private final String teacherId;
+ private String name;
+ private double salary;
+
+ public Teacher(String name, double salary) {
+ this.teacherId = UUID.randomUUID().toString();
+ setName(name);
+ setSalary(salary);
+ }
+
+ public String getTeacherId() {
+ return teacherId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public double getSalary() {
+ return salary;
+ }
+
+ public boolean setSalary(double salary) {
+ if (salary < 0) {
+ return false;
+ } else {
+ this.salary = salary;
+ }
+ return true;
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/ApplicationTest.java b/src/test/java/ApplicationTest.java
new file mode 100644
index 0000000..a032f48
--- /dev/null
+++ b/src/test/java/ApplicationTest.java
@@ -0,0 +1,170 @@
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class ApplicationTest {
+
+ private final InputStream originalSystemIn = System.in;
+ private final PrintStream originalSystemOut = System.out;
+ private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ private ByteArrayInputStream input;
+ Application application;
+
+
+
+ @BeforeEach
+ public void setUpStreams() {
+ System.setOut(new PrintStream(outputStream));
+ }
+
+ @Test
+ public void testCreateSchoolName() {
+ input = new ByteArrayInputStream("Ironhack School\n".getBytes());
+ System.setIn(input);
+
+ application = new Application();
+ application.createSchoolName();
+ assertEquals("Welcome to the School Application\nPlease enter the name of the school:Your school is: Ironhack School\n", outputStream.toString());
+ }
+
+ @Test
+ public void testNumberOfComponentsWithValidInput() {
+ input = new ByteArrayInputStream("5\n".getBytes());
+ System.setIn(input);
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outputStream));
+
+ application = new Application();
+ int result = application.numberOfComponents(SchoolComponents.TEACHERS);
+
+ assertEquals(5, result);
+ assertTrue(outputStream.toString().contains("In your school there are 5 teachers"));
+
+
+ }
+
+ @Test
+ public void testNumberOfComponentsWithInvalidInput() {
+ input = new ByteArrayInputStream("invalid\n5\n".getBytes());
+ System.setIn(input);
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outputStream));
+
+ application = new Application();
+ int result = application.numberOfComponents(SchoolComponents.TEACHERS);
+
+ assertEquals(5, result);
+ assertTrue(outputStream.toString().contains("In your school there are 5 teachers"));
+
+
+ }
+
+ @Test
+ public void testValidateInputWithValidInput() {
+ input = new ByteArrayInputStream("Ironhack\n".getBytes());
+ System.setIn(input);
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outputStream));
+
+ application = new Application();
+
+ String result = application.validateInput("Name", "Name cannot be empty", "Name cannot contain numbers");
+
+ assertEquals("Ironhack", result);
+ }
+
+ @Test
+ public void testTeacherDetail() {
+ input = new ByteArrayInputStream("1\nJohn\n3000\n".getBytes());
+ System.setIn(input);
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outputStream));
+
+ application = new Application();
+
+ Map result = application.teacherDetails();
+
+ assertNotNull(result);
+ assertEquals(1, result.size());
+
+ Teacher teacher = result.values().iterator().next();
+ assertEquals("John", teacher.getName());
+ assertEquals(3000.0, teacher.getSalary());
+
+ assertTrue(outputStream.toString().contains("John"));
+ assertTrue(outputStream.toString().contains("3000.0"));
+ }
+
+
+
+ @Test
+ public void testStudentDetail() {
+ input = new ByteArrayInputStream("1\nJohn\nCasa\ndsdad@fds.com".getBytes());
+ System.setIn(input);
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outputStream));
+
+ application = new Application();
+
+ Map result = application.studentDetails();
+
+ assertNotNull(result);
+ assertEquals(1, result.size());
+
+ Student student = result.values().iterator().next();
+ assertEquals("John", student.getName());
+ assertEquals("Casa", student.getAddress());
+ assertEquals("dsdad@fds.com", student.getEmail());
+
+ assertTrue(outputStream.toString().contains("John"));
+ assertTrue(outputStream.toString().contains("Casa"));
+ assertTrue(outputStream.toString().contains("dsdad@fds.com"));
+ }
+
+ @Test
+ public void testCourseDetail() {
+ input = new ByteArrayInputStream("1\nEnglish\n3000\n".getBytes());
+ System.setIn(input);
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outputStream));
+
+ application = new Application();
+
+ Map result = application.courseDetails();
+
+ assertNotNull(result);
+ assertEquals(1, result.size());
+
+ Course student = result.values().iterator().next();
+ assertEquals("English", student.getName());
+ assertEquals(3000.0, student.getPrice());
+
+
+ assertTrue(outputStream.toString().contains("English"));
+ assertTrue(outputStream.toString().contains("3000.0"));
+ }
+
+
+
+
+ @AfterEach
+ public void restoreSystemInputOutput() {
+ System.setIn(originalSystemIn);
+ System.setOut(originalSystemOut);
+ }
+}
+
diff --git a/src/test/java/Command9to10Test.java b/src/test/java/Command9to10Test.java
new file mode 100644
index 0000000..4752c3f
--- /dev/null
+++ b/src/test/java/Command9to10Test.java
@@ -0,0 +1,110 @@
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class Command9to10Test {
+ Map testCourseList = new LinkedHashMap<>();
+ Map testStudentList = new LinkedHashMap<>();
+ Map testTeacherList = new LinkedHashMap<>();
+ Commands commandsInstance = new Commands(testCourseList, testStudentList, testTeacherList);
+ Course sampleCourse;
+ Teacher sampleTeacher;
+ ByteArrayOutputStream outputStream;
+ Student sampleStudent;
+
+ @BeforeEach
+ public void setUp() {
+ // Redirect System.out to capture the output
+ outputStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outputStream));
+
+ // Create sample data and add it to the coursesMap
+ sampleCourse = new Course("Math", 200.0);
+ testCourseList.put(sampleCourse.getCourseId(), sampleCourse);
+
+ // Create sample data and add it to the teachersMap
+ sampleTeacher = new Teacher("Prof. Smith", 500.0);
+ testTeacherList.put(sampleTeacher.getTeacherId(), sampleTeacher);
+
+ // Create sample data and add it to the testStudentList
+ sampleStudent = new Student("John Smith", "123 Main St", "johnS@example.com");
+ testStudentList.put(sampleStudent.getStudentId(), sampleStudent);
+ }
+
+ @Test
+ public void testShowProfitPositive() {
+ // Assign Teacher to Course
+ sampleCourse.setTeacher(sampleTeacher);
+
+ // SetMoneyEarned
+ sampleCourse.setMoney_earned(1000);
+
+ // Call the method to be tested
+ commandsInstance.ShowProfit();
+
+ // Assert on the expected output
+ String expectedOutput = "Total profit: " + 500.0 + "€\n";
+
+ assertEquals(expectedOutput, outputStream.toString());
+ }
+
+ @Test
+ public void testShowProfitNegative() {
+ // Assign Teacher to Course
+ sampleCourse.setTeacher(sampleTeacher);
+
+ // SetMoneyEarned
+ sampleCourse.setMoney_earned(100);
+
+ // Call the method to be tested
+ commandsInstance.ShowProfit();
+
+ // Assert on the expected output
+ String expectedOutput = "Total profit: " + -400.0 + "€\n";
+
+ assertEquals(expectedOutput, outputStream.toString());
+ }
+
+ @Test
+ public void testShowCourseStudents() {
+ // Enroll student to Course
+ sampleCourse.courseEnroll(sampleStudent);
+
+ // Call the method to be tested
+ commandsInstance.ShowCourseStudents(sampleCourse.getCourseId());
+
+ // Assert on the expected output
+ String expectedOutput = sampleCourse.getName() + " students:\n"
+ + sampleStudent.getStudentId() + ": " + sampleStudent.getName() + "\n";
+
+ assertEquals(expectedOutput, outputStream.toString());
+ }
+
+ @Test
+ public void testShowCourseStudentsEmpty() {
+ // Call the method to be tested
+ commandsInstance.ShowCourseStudents(sampleCourse.getCourseId());
+
+ // Assert on the expected output
+ String expectedOutput = sampleCourse.getName() + " has no students enrolled\n";
+
+ assertEquals(expectedOutput, outputStream.toString());
+ }
+
+
+ @AfterEach
+ public void clear() {
+ // Reset the testCourseList
+ testCourseList.clear();
+
+ // Reset System.out
+ System.setOut(System.out);
+ }
+}
diff --git a/src/test/java/Commands1to2Test.java b/src/test/java/Commands1to2Test.java
new file mode 100644
index 0000000..56d277a
--- /dev/null
+++ b/src/test/java/Commands1to2Test.java
@@ -0,0 +1,64 @@
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class Commands1to2Test {
+ Map testCourseList = new LinkedHashMap<>();
+ Map testStudentList = new LinkedHashMap<>();
+ Map testTeacherList = new LinkedHashMap<>();
+ Commands commandsInstance = new Commands(testCourseList, testStudentList, testTeacherList);
+
+ private Student student;
+ private Teacher teacher;
+ private Course course;
+
+ @BeforeEach
+ public void setUp() {
+
+ // Create sample data and add it to the coursesMap
+ course = new Course("Math", 200.0);
+ testCourseList.put(course.getCourseId(), course);
+
+ // Create sample data and add it to the teachersMap
+ teacher = new Teacher("Prof. Smith", 500.0);
+ testTeacherList.put(teacher.getTeacherId(), teacher);
+
+ // Create sample data and add it to the testStudentList
+ student = new Student("John Smith", "123 Main St", "johnS@example.com");
+ testStudentList.put(student.getStudentId(), student);
+ }
+
+ @AfterEach
+ public void cleanUp(){
+ testCourseList.clear();
+ testStudentList.clear();
+ testStudentList.clear();
+ }
+
+ @Test
+ public void enrollTest(){
+
+ commandsInstance.enroll(student.getStudentId(), course.getCourseId());
+
+ assertEquals(1, testCourseList.size());
+ assertEquals("Math", testCourseList.get(course.getCourseId()).getName());
+ }
+
+ @Test
+ public void assignTest(){
+
+ commandsInstance.assign(teacher.getTeacherId(), course.getCourseId());
+
+ assertEquals(1, testCourseList.size());
+ assertEquals("Prof. Smith", testTeacherList.get(teacher.getTeacherId()).getName());
+ assertEquals("Math", testCourseList.get(course.getCourseId()).getName());
+ }
+
+}
diff --git a/src/test/java/Commands3To8Test.java b/src/test/java/Commands3To8Test.java
new file mode 100644
index 0000000..a708908
--- /dev/null
+++ b/src/test/java/Commands3To8Test.java
@@ -0,0 +1,212 @@
+import org.junit.jupiter.api.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class Commands3To8Test {
+ Map testCourseList = new LinkedHashMap<>();
+ Map testStudentList = new LinkedHashMap<>();
+ Map testTeacherList = new LinkedHashMap<>();
+ Commands commandsInstance = new Commands(testCourseList, testStudentList, testTeacherList);
+
+ @Test
+ public void testShowCourses() {
+ // Redirect System.out to capture the output
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outputStream));
+
+ // Create sample data and add it to the coursesMap
+ Course sampleCourse = new Course("Math", 100.0);
+ testCourseList.put(sampleCourse.getCourseId(), sampleCourse);
+ Course sampleCourse2 = new Course("Science", 150.0);
+ testCourseList.put(sampleCourse2.getCourseId(), sampleCourse2);
+ Course sampleCourse3 = new Course("History", 200.0);
+ testCourseList.put(sampleCourse3.getCourseId(), sampleCourse3);
+
+ // Call the method to be tested
+ commandsInstance.ShowCourses();
+
+ // Assert on the expected output
+ String expectedOutput = "List of Courses: \n" +
+ sampleCourse.getCourseId() + " : Math\n" +
+ sampleCourse2.getCourseId() + " : Science\n" +
+ sampleCourse3.getCourseId() + " : History\n";
+
+ assertEquals(expectedOutput, outputStream.toString());
+
+ // Reset System.out
+ System.setOut(System.out);
+
+ // Reset the testCourseList
+ testCourseList.clear();
+ }
+
+ @Test
+ void testLookupCourse() {
+
+ // Redirect System.out to capture the output
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outputStream));
+
+ // Create sample data and add it to the coursesMap
+ Course sampleCourse = new Course("Math", 100.0);
+ testCourseList.put(sampleCourse.getCourseId(), sampleCourse);
+ Course sampleCourse2 = new Course("Science", 150.0);
+ testCourseList.put(sampleCourse2.getCourseId(), sampleCourse2);
+ Course sampleCourse3 = new Course("History", 200.0);
+ testCourseList.put(sampleCourse3.getCourseId(), sampleCourse3);
+
+ // Call the method to be tested
+ commandsInstance.LookupCourse(sampleCourse.getCourseId());
+ commandsInstance.LookupCourse(sampleCourse2.getCourseId());
+ commandsInstance.LookupCourse(sampleCourse3.getCourseId());
+
+ // Assert on the expected output
+ String expectedOutput = "Course ID: " + sampleCourse.getCourseId() + "\nCourse Name: Math\nCourse Price: 100.0\nCourse Money Earned: 0.0\nCourse Teacher: No teacher assigned\n" +
+ "Course ID: " + sampleCourse2.getCourseId() + "\nCourse Name: Science\nCourse Price: 150.0\nCourse Money Earned: 0.0\nCourse Teacher: No teacher assigned\n" +
+ "Course ID: " + sampleCourse3.getCourseId() + "\nCourse Name: History\nCourse Price: 200.0\nCourse Money Earned: 0.0\nCourse Teacher: No teacher assigned\n";
+ assertEquals(expectedOutput, outputStream.toString());
+
+
+ // Reset System.out
+ System.setOut(System.out);
+
+ // Reset the testCourseList
+ testCourseList.clear();
+ }
+
+ @Test
+ void testShowStudents() {
+ // Redirect System.out to capture the output
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outputStream));
+
+ // Create sample data and add it to the testStudentList
+ Student sampleStudent = new Student("John Doe", "123 Main St", "123@gmail.com");
+ testStudentList.put(sampleStudent.getStudentId(), sampleStudent);
+ Student sampleStudent2 = new Student("Jane Doe", "123 Main St", "234@gmailcom");
+ testStudentList.put(sampleStudent2.getStudentId(), sampleStudent2);
+ Student sampleStudent3 = new Student("John Smith", "123 Main St", "345@gmail.com");
+ testStudentList.put(sampleStudent3.getStudentId(), sampleStudent3);
+
+
+ // Call the method to be tested
+ commandsInstance.ShowStudents();
+
+ // Assert on the expected output
+ String expectedOutput = "List of Students: \n" +
+ sampleStudent.getStudentId() + " : John Doe\n" +
+ sampleStudent2.getStudentId() + " : Jane Doe\n" +
+ sampleStudent3.getStudentId() + " : John Smith\n";
+
+ assertEquals(expectedOutput, outputStream.toString());
+
+ // Reset System.out
+ System.setOut(System.out);
+
+ // Reset the testStudentList
+ testStudentList.clear();
+ }
+
+ @Test
+ void testLookupStudent() {
+ // Create sample data and add it to the testStudentList
+ Student sampleStudent = new Student("John Doe", "123 Main St", "john@example.com");
+ testStudentList.put(sampleStudent.getStudentId(), sampleStudent);
+ Student sampleStudent2 = new Student("Jane Doe", "123 Main St", "jane@example.com");
+ testStudentList.put(sampleStudent2.getStudentId(), sampleStudent2);
+ Student sampleStudent3 = new Student("John Smith", "123 Main St", "johnS@example.com");
+ testStudentList.put(sampleStudent3.getStudentId(), sampleStudent3);
+
+ // Redirect System.out to capture the output
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outputStream));
+
+ // Call the method to be tested
+ commandsInstance.LookupStudent(sampleStudent.getStudentId());
+ commandsInstance.LookupStudent(sampleStudent2.getStudentId());
+ commandsInstance.LookupStudent(sampleStudent3.getStudentId());
+
+ // Assert on the expected output
+ String expectedOutput = "Student ID: " + sampleStudent.getStudentId() + "\nStudent Name: John Doe\nStudent Address: 123 Main St\nStudent Email: john@example.com\nStudent Course: No course enrolled\n"
+ + "Student ID: " + sampleStudent2.getStudentId() + "\nStudent Name: Jane Doe\nStudent Address: 123 Main St\nStudent Email: jane@example.com\nStudent Course: No course enrolled\n" +
+ "Student ID: " + sampleStudent3.getStudentId() + "\nStudent Name: John Smith\nStudent Address: 123 Main St\nStudent Email: johnS@example.com\nStudent Course: No course enrolled\n";
+ assertEquals(expectedOutput, outputStream.toString());
+
+ // Reset System.out
+ System.setOut(System.out);
+
+ // Reset the testStudentList
+ testStudentList.clear();
+ }
+
+ @Test
+ void testShowTeachers() {
+ // Redirect System.out to capture the output
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outputStream));
+
+ // Create sample data and add it to the testTeacherList
+ Teacher sampleTeacher = new Teacher("Prof. Smith", 5000.0);
+ testTeacherList.put(sampleTeacher.getTeacherId(), sampleTeacher);
+ Teacher sampleTeacher2 = new Teacher("Prof. Doe", 6000.0);
+ testTeacherList.put(sampleTeacher2.getTeacherId(), sampleTeacher2);
+ Teacher sampleTeacher3 = new Teacher("Prof. Johnson", 7000.0);
+ testTeacherList.put(sampleTeacher3.getTeacherId(), sampleTeacher3);
+
+ // Call the method to be tested
+ commandsInstance.ShowTeachers();
+
+ // Assert on the expected output
+ String expectedOutput = "List of Teachers: \n" +
+ sampleTeacher.getTeacherId() + " : Prof. Smith\n" +
+ sampleTeacher2.getTeacherId() + " : Prof. Doe\n" +
+ sampleTeacher3.getTeacherId() + " : Prof. Johnson\n";
+
+ assertEquals(expectedOutput, outputStream.toString());
+
+ // Reset System.out
+ System.setOut(System.out);
+
+ // Reset the testTeacherList
+ testTeacherList.clear();
+ }
+
+ @Test
+ void testLookupTeacher() {
+ // Create sample data and add it to the testTeacherList
+ Teacher sampleTeacher = new Teacher("Prof. Smith", 5000.0);
+ testTeacherList.put(sampleTeacher.getTeacherId(), sampleTeacher);
+ Teacher sampleTeacher2 = new Teacher("Prof. Doe", 6000.0);
+ testTeacherList.put(sampleTeacher2.getTeacherId(), sampleTeacher2);
+ Teacher sampleTeacher3 = new Teacher("Prof. Johnson", 7000.0);
+ testTeacherList.put(sampleTeacher3.getTeacherId(), sampleTeacher3);
+
+ // Redirect System.out to capture the output
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(outputStream));
+
+ // Call the method to be tested
+ commandsInstance.LookupTeacher(sampleTeacher.getTeacherId());
+ commandsInstance.LookupTeacher(sampleTeacher2.getTeacherId());
+ commandsInstance.LookupTeacher(sampleTeacher3.getTeacherId());
+
+ // Assert on the expected output
+ String expectedOutput = "Teacher ID: " + sampleTeacher.getTeacherId()+ "\nTeacher Name: Prof. Smith\nTeacher Salary: 5000.0\n"
+ + "Teacher ID: " + sampleTeacher2.getTeacherId()+ "\nTeacher Name: Prof. Doe\nTeacher Salary: 6000.0\n"
+ + "Teacher ID: " + sampleTeacher3.getTeacherId()+ "\nTeacher Name: Prof. Johnson\nTeacher Salary: 7000.0\n";
+ assertEquals(expectedOutput, outputStream.toString());
+
+ // Reset System.out
+ System.setOut(System.out);
+
+ // Reset the testTeacherList
+ testTeacherList.clear();
+ }
+
+}
diff --git a/src/test/java/CourseTest.java b/src/test/java/CourseTest.java
new file mode 100644
index 0000000..25d8e41
--- /dev/null
+++ b/src/test/java/CourseTest.java
@@ -0,0 +1,27 @@
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class CourseTest {
+
+ private Course course;
+
+ @BeforeEach
+ public void setUp(){
+ course = new Course("Math", 120);
+ }
+
+ @Test
+ public void returns(){
+ assertEquals("Math", course.getName());
+ }
+
+ @Test
+ public void priceTest(){
+ assertEquals(120, course.getPrice());
+ }
+
+}
diff --git a/src/test/java/test.java b/src/test/java/test.java
new file mode 100644
index 0000000..e3bba97
--- /dev/null
+++ b/src/test/java/test.java
@@ -0,0 +1,4 @@
+
+public class test {
+
+}
diff --git a/target/classes/Application.class b/target/classes/Application.class
new file mode 100644
index 0000000..e676d3c
Binary files /dev/null and b/target/classes/Application.class differ
diff --git a/target/classes/CommandEnum.class b/target/classes/CommandEnum.class
new file mode 100644
index 0000000..eafb0df
Binary files /dev/null and b/target/classes/CommandEnum.class differ
diff --git a/target/classes/Commands$1.class b/target/classes/Commands$1.class
new file mode 100644
index 0000000..428ce36
Binary files /dev/null and b/target/classes/Commands$1.class differ
diff --git a/target/classes/Commands.class b/target/classes/Commands.class
new file mode 100644
index 0000000..e10cd34
Binary files /dev/null and b/target/classes/Commands.class differ
diff --git a/target/classes/Course.class b/target/classes/Course.class
new file mode 100644
index 0000000..38f2744
Binary files /dev/null and b/target/classes/Course.class differ
diff --git a/target/classes/Main.class b/target/classes/Main.class
new file mode 100644
index 0000000..1e793e3
Binary files /dev/null and b/target/classes/Main.class differ
diff --git a/target/classes/SchoolComponents.class b/target/classes/SchoolComponents.class
new file mode 100644
index 0000000..5e1d677
Binary files /dev/null and b/target/classes/SchoolComponents.class differ
diff --git a/target/classes/Student.class b/target/classes/Student.class
new file mode 100644
index 0000000..d79dc7b
Binary files /dev/null and b/target/classes/Student.class differ
diff --git a/target/classes/Teacher.class b/target/classes/Teacher.class
new file mode 100644
index 0000000..6f5d736
Binary files /dev/null and b/target/classes/Teacher.class differ
diff --git a/target/test-classes/ApplicationTest.class b/target/test-classes/ApplicationTest.class
new file mode 100644
index 0000000..e36170c
Binary files /dev/null and b/target/test-classes/ApplicationTest.class differ
diff --git a/target/test-classes/Command9to10Test.class b/target/test-classes/Command9to10Test.class
new file mode 100644
index 0000000..0c4ab9f
Binary files /dev/null and b/target/test-classes/Command9to10Test.class differ
diff --git a/target/test-classes/Commands1to2Test.class b/target/test-classes/Commands1to2Test.class
new file mode 100644
index 0000000..8a5e56a
Binary files /dev/null and b/target/test-classes/Commands1to2Test.class differ
diff --git a/target/test-classes/Commands3To8Test.class b/target/test-classes/Commands3To8Test.class
new file mode 100644
index 0000000..8b969ae
Binary files /dev/null and b/target/test-classes/Commands3To8Test.class differ
diff --git a/target/test-classes/CourseTest.class b/target/test-classes/CourseTest.class
new file mode 100644
index 0000000..d6bbb01
Binary files /dev/null and b/target/test-classes/CourseTest.class differ
diff --git a/target/test-classes/test.class b/target/test-classes/test.class
new file mode 100644
index 0000000..20d2255
Binary files /dev/null and b/target/test-classes/test.class differ