diff --git a/.idea/Iron-hack-school.iml b/.idea/Iron-hack-school.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/.idea/Iron-hack-school.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ironhack-school/.gitignore b/Ironhack-school/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/Ironhack-school/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/Ironhack-school/.idea/encodings.xml b/Ironhack-school/.idea/encodings.xml
new file mode 100644
index 0000000..aa00ffa
--- /dev/null
+++ b/Ironhack-school/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ironhack-school/.idea/misc.xml b/Ironhack-school/.idea/misc.xml
new file mode 100644
index 0000000..cb7de09
--- /dev/null
+++ b/Ironhack-school/.idea/misc.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ironhack-school/.idea/vcs.xml b/Ironhack-school/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/Ironhack-school/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ironhack-school/.idea/workspace.xml b/Ironhack-school/.idea/workspace.xml
new file mode 100644
index 0000000..edfb479
--- /dev/null
+++ b/Ironhack-school/.idea/workspace.xml
@@ -0,0 +1,236 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ "associatedIndex": 8
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1708762591629
+
+
+ 1708762591629
+
+
+
+ 1710279193807
+
+
+
+ 1710279193807
+
+
+
+ 1710358013399
+
+
+
+ 1710358013399
+
+
+
+ 1710360178349
+
+
+
+ 1710360178349
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Ironhack-school/pom.xml b/Ironhack-school/pom.xml
new file mode 100644
index 0000000..1829019
--- /dev/null
+++ b/Ironhack-school/pom.xml
@@ -0,0 +1,49 @@
+
+ 4.0.0
+
+ ironhack.com
+ Ironhack-school
+ 1.0-SNAPSHOT
+ jar
+
+ Ironhack-school
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+ org.projectlombok
+ lombok
+ 1.18.30
+ provided
+
+
+ org.junit.jupiter
+ junit-jupiter
+ 5.8.1
+ test
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 9
+
+
+
+
+
diff --git a/Ironhack-school/src/files/Courses.csv b/Ironhack-school/src/files/Courses.csv
new file mode 100644
index 0000000..df51637
--- /dev/null
+++ b/Ironhack-school/src/files/Courses.csv
@@ -0,0 +1,12 @@
+name,price,money_earned
+web development,3500,0
+java backend,7500,0
+data science,5000,0
+mobile development,4000,0
+cloud computing,6000,0
+network security,5500,0
+backend development,7000,0
+frontend development,4500,0
+machine learning,6500,0
+artificial intelligence,8500,0
+game development,4800,0
diff --git a/Ironhack-school/src/files/School.csv b/Ironhack-school/src/files/School.csv
new file mode 100644
index 0000000..eb042ab
--- /dev/null
+++ b/Ironhack-school/src/files/School.csv
@@ -0,0 +1,2 @@
+name,teacher_number,courses_number,student_number
+iron_copy,1,2,2
\ No newline at end of file
diff --git a/Ironhack-school/src/files/Students.csv b/Ironhack-school/src/files/Students.csv
new file mode 100644
index 0000000..629b8ff
--- /dev/null
+++ b/Ironhack-school/src/files/Students.csv
@@ -0,0 +1,21 @@
+name,address,email,courseList
+estefania,barcelona,estefania@ironhack.com,[]
+ivan,barcelona,ivan@ironhack.com,[]
+john,paris,john@example.com,[Data Science |Web Development]
+mary,new york,mary@example.com,[UX/UI Design]
+peter,london,peter@example.com,[Data Analytics | Cybersecurity]
+lisa,berlin,lisa@example.com,[Web Development | Digital Marketing]
+michael,tokyo,michael@example.com,[Data Science]
+sarah,sydney,sarah@example.com,[UX/UI Design]
+david,toronto,david@example.com,[Data Analytics]
+emma,milan,emma@example.com,[Web Development]
+james,seoul,james@example.com,[Data Science]
+sophia,madrid,sophia@example.com,[Digital Marketing]
+william,rome,william@example.com,[UX/UI Design]
+olivia,mexico city,olivia@example.com,[Data Analytics]
+alexandra,moscow,alexandra@example.com,[Web Development]
+ethan,mumbai,ethan@example.com,[Data Science]
+ava,bangkok,ava@example.com,[Digital Marketing]
+benjamin,dubai,benjamin@example.com,[UX/UI Design]
+mia,rio de janeiro,mia@example.com,[Data Analytics]
+charlotte,cairo,charlotte@example.com,[Web Development]
diff --git a/Ironhack-school/src/files/Teachers.csv b/Ironhack-school/src/files/Teachers.csv
new file mode 100644
index 0000000..d733ec8
--- /dev/null
+++ b/Ironhack-school/src/files/Teachers.csv
@@ -0,0 +1,11 @@
+name,salary
+antonio,2000
+maria,2500
+jose,2200
+ana,2300
+carlos,2100
+laura,2400
+pablo,2150
+sofia,2250
+juan,2050
+elena,2350
\ No newline at end of file
diff --git a/Ironhack-school/src/main/java/ironhack/com/App.java b/Ironhack-school/src/main/java/ironhack/com/App.java
new file mode 100644
index 0000000..3dfacac
--- /dev/null
+++ b/Ironhack-school/src/main/java/ironhack/com/App.java
@@ -0,0 +1,270 @@
+package ironhack.com;
+
+import java.util.*;
+
+import static ironhack.com.ReadCsvInfo.school_creation_csv;
+import static ironhack.com.Utils.*;
+
+public class App {
+ public static void main(String[] args) {
+ Scanner scanner = new Scanner(System.in);
+ School school = null;
+ boolean is_finish = false;
+ do {
+ System.out.println("*******School Management System******");
+ System.out.println("Choose a Command From the List");
+ System.out.println("1-CREATE SCHOOL BY READING CSV");
+ System.out.println("2-CREATE SCHOOL MANUALLY ");
+ System.out.println("3-LAUNCH COMMANDS ");
+ System.out.println("4-EXIT ");
+ String value = scanner.nextLine();
+ switch (value) {
+ case "1":
+ System.out.println("READING CSV.....");
+ school = school_creation_csv();
+ break;
+ case "2":
+ school = create_school_by_std_input(scanner);
+ break;
+ case "3":
+ if (school != null) {
+ show_commands_list(scanner, school);
+ } else {
+ System.out.println("School has not been initialized. Use command 1 or 2");
+ }
+ break;
+
+ case "4":
+ is_finish = true;
+ System.out.println("SEE YOU SOON!");
+ break;
+
+ default:
+ System.out.println("Invalid input");
+ }
+
+ } while (!is_finish);
+
+
+
+
+ }
+
+ public static School create_school_by_std_input(Scanner scanner){
+
+ System.out.println("Let's create an School");
+ System.out.println("Enter a Name:");
+ String name = validateNameOf(scanner);
+
+ System.out.println("how many teachers should be created?");
+ int teacher_number = validateNumberOf(scanner, 1);
+ System.out.println(teacher_number);
+ List teachers = create_teachers(scanner, teacher_number);
+
+ System.out.println("how many courses should be created?");
+ int courses_number = validateNumberOf(scanner, 1);
+ System.out.println(courses_number);
+ List courses = create_course(scanner, courses_number);
+
+
+ System.out.println("how many students should be created?");
+ int students_number = validateNumberOf(scanner, 1);
+ System.out.println(students_number);
+ List students = create_students(scanner, students_number);
+
+ return create_school(name, teachers, courses, students);
+
+ }
+
+ public static List create_teachers(Scanner scanner, int teacher_number) {
+
+ List teachers_list = new ArrayList<>();
+ for (int i = 0; i < teacher_number; i++) {
+ System.out.println("Let's create teacher " + (i + 1));
+ System.out.println("Enter Name:");
+ String teacher_name = validateNameOf(scanner);
+
+ System.out.println("Enter Salary (Ex 34000): ");
+ int teacher_salary = validateNumberOf(scanner, 0);
+ // Validate Range of Salaries
+ teachers_list.add(new Teacher(teacher_name, teacher_salary));
+ }
+ return teachers_list;
+
+ }
+
+ public static List create_course(Scanner scanner, int course_number) {
+
+ List course_list = new ArrayList<>();
+ for (int i = 0; i < course_number; i++) {
+ System.out.println("Let's create a course " + (i + 1));
+ System.out.println("Enter Name:");
+ String course_name = validateNameOf(scanner);
+
+ System.out.println("Enter Price: ");
+ double price = validateDoubleOf(scanner);
+
+ course_list.add(new Course(course_name, price));
+ }
+ return course_list;
+
+ }
+
+ public static List create_students(Scanner scanner, int students_number) {
+
+ List students_list = new ArrayList<>();
+ for (int i = 0; i < students_number; i++) {
+ System.out.println("Let's create student " + (i + 1));
+ System.out.println("Enter Name:");
+ String student_name = validateNameOf(scanner);
+ ;
+
+ System.out.println("Enter Address: ");
+ String address = scanner.nextLine();
+
+ System.out.println("Enter Email: ");
+ String email = validateEmailOf(scanner);
+
+ students_list.add(new Student(student_name, address, email));
+ }
+ return students_list;
+
+ }
+
+ public static School create_school(String name, List teachers, List courses, List students) {
+ School school = new School(name);
+ school.setListToStudentMap(students);
+ school.setListToTeacherMap(teachers);
+ school.setListToCourseMap(courses);
+ return school;
+ }
+
+ public static void show_commands_list(Scanner scanner, School school) {
+ boolean is_finish = false;
+ do {
+ System.out.println("*******School Management System******");
+ System.out.println("Choose a Command From the List");
+ System.out.println("1-ENROLL [STUDENT_ID] [COURSE_ID]");
+ System.out.println("2-ASSIGN [TEACHER_ID] [COURSE_ID]");
+ System.out.println("3-SHOW COURSES");
+ System.out.println("4-LOOKUP COURSE [COURSE_ID]");
+ System.out.println("5-SHOW STUDENTS");
+ System.out.println("6-LOOKUP STUDENT [STUDENT_ID]");
+ System.out.println("7-SHOW TEACHERS");
+ System.out.println("8-LOOKUP TEACHER [TEACHER_ID]");
+ System.out.println("9-SHOW PROFIT");
+ System.out.println("10-Go back");
+ System.out.println("h-help");
+ String value = scanner.nextLine();
+ String result;
+ String student_id ;
+ String teacher_id;
+ String course_id;
+ switch (value) {
+ case "1":
+ System.out.println("1-ENROLL [STUDENT_ID] [COURSE_ID]");
+ Student student = null;
+ System.out.println("Enter a [STUDENT_ID]");
+ while (student == null) {
+ student_id = Long.toString(validateIdOf(scanner));
+ student = school.findStudentById(student_id);
+ if (student == null) {
+ System.out.println("Student with ID " + student_id + " not found. Please try again.");
+ } else {
+ System.out.println("Student found:");
+ student.printInfo();
+ }
+ }
+
+ // Similar logic applies to course
+ System.out.println("Now Enter a [COURSE_ID]");
+ Course course = null;
+ while (course == null) {
+ course_id = Long.toString(validateIdOf(scanner));
+ course = school.lookupCourse(course_id);
+ if (course == null) {
+ System.out.println("Course with ID " + course_id + " not found. Please try again.");
+ } else {
+ System.out.println("Course found:");
+ course.printInfo();
+ }
+ }
+ break;
+ case "2":
+ System.out.println("2-ASSIGN [TEACHER_ID] [COURSE_ID]");
+
+ System.out.println("Enter a [TEACHER_ID]");
+ teacher_id = Long.toString(validateIdOf(scanner));
+ Teacher teacher = school.findTeacherById(teacher_id);
+ if(teacher ==null) {
+ System.out.println("Teacher not Found");
+ break;
+ }
+ System.out.println("Now Enter a [COURSE_ID]");
+ course_id = Long.toString(validateIdOf(scanner));
+ Course course_retrieve = school.findCourseById(course_id);
+
+ if(course_retrieve==null) {
+ System.out.println("Course not Found");
+ break;
+ }
+ school.assignTeacherToCourse(teacher_id, course_id);
+ break;
+ case "3":
+ System.out.println("3-SHOW COURSES");
+ school.showCourses();
+ break;
+ case "4":
+ System.out.println("4-LOOKUP COURSE [COURSE_ID]");
+ System.out.println("Enter a [COURSE_ID]");
+ course_id = Long.toString(validateIdOf(scanner));
+ school.lookupCourse(course_id);
+ break;
+ case "5":
+ System.out.println("5-SHOW STUDENTS");
+ school.showStudents();
+ break;
+ case "6":
+ System.out.println("6-LOOKUP STUDENT [STUDENT_ID]");
+ System.out.println("Enter a [STUDENT_ID]");
+ student_id = Long.toString(validateIdOf(scanner));
+ school.lookupStudent(student_id);
+ break;
+ case "7":
+ System.out.println("7-SHOW TEACHERS");
+ school.showTeachers();
+ break;
+ case "8":
+ System.out.println("8-LOOKUP TEACHER [TEACHER_ID]");
+ System.out.println("Enter a [TEACHER_ID]");
+ teacher_id = Long.toString(validateIdOf(scanner));
+ school.lookupTeacher(teacher_id);
+ break;
+ case "9":
+ System.out.println("9-SHOW PROFIT");
+ school.showProfit();
+
+ break;
+ case "h":
+ System.out.println("ENROLL [STUDENT_ID] [COURSE_ID]: 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");
+ System.out.println("ASSIGN [TEACHER_ID] [COURSE_ID]: This command will help assign the teacher specified to the corresponding course");
+ System.out.println("SHOW COURSES: This command will display a list of all courses");
+ System.out.println("LOOKUP COURSE [COURSE_ID]: This command will display the full details of the specified course");
+ System.out.println("SHOW STUDENTS: This command will display a list of all students");
+ System.out.println("LOOKUP STUDENT [STUDENT_ID]: This command will display the full details of the specified student");
+ System.out.println("SHOW TEACHERS: This command will display a list of all teachers");
+ System.out.println("LOOKUP TEACHER [TEACHER_ID]: This command will display the full details of the specified teacher");
+ System.out.println("SHOW PROFIT: This command will calculate (The total money earned from all courses) - (The sum of all the teachers' salaries) and return the result");
+ break;
+ case "10":
+ is_finish = true;
+ break;
+
+ default:
+ System.out.println("Invalid input");
+ }
+
+ } while (!is_finish);
+ }
+
+}
diff --git a/Ironhack-school/src/main/java/ironhack/com/Course.java b/Ironhack-school/src/main/java/ironhack/com/Course.java
new file mode 100644
index 0000000..f201184
--- /dev/null
+++ b/Ironhack-school/src/main/java/ironhack/com/Course.java
@@ -0,0 +1,55 @@
+package ironhack.com;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+@Getter
+@Setter
+public class Course {
+ private String Id;
+ private String name;
+ private double price;
+ private double money_earned;
+ private Teacher teacher;
+
+ public void setId(){
+ setId(Utils.generateSerialId());
+ }
+ public Course(String name) {
+ setId();
+ setName(name);
+ }
+
+ public Course(String name, double price){
+ setId();
+ setName(name);
+ setPrice(price);
+ }
+ public Course(String name, double price,Teacher teacher){
+ setId();
+ setName(name);
+ setPrice(price);
+ setTeacher(teacher);
+ }
+ public void assign(Teacher teacher) {
+ setTeacher(teacher);
+ }
+
+ public void printInfo() {
+ System.out.println("Id: " + getId()
+ + ", Name: " + getName()
+ + ", Price: " + getPrice()
+ + ", Money Earned: " + getMoney_earned()
+ + ", Teacher: " +(getTeacher() != null ? getTeacher().getName() : "N/A"));
+ }
+
+ public static Course findCourseByName(List courses, String courseName) {
+ for (Course course : courses) {
+ if (course.getName().equalsIgnoreCase(courseName)) {
+ return course;
+ }
+ }
+ return null;
+ }
+}
diff --git a/Ironhack-school/src/main/java/ironhack/com/Person.java b/Ironhack-school/src/main/java/ironhack/com/Person.java
new file mode 100644
index 0000000..54bda54
--- /dev/null
+++ b/Ironhack-school/src/main/java/ironhack/com/Person.java
@@ -0,0 +1,16 @@
+package ironhack.com;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public abstract class Person {
+ private String id;
+ private String name;
+
+ public Person(String name){
+ setName(name);
+ setId(Utils.generateSerialId());
+ }
+
+}
diff --git a/Ironhack-school/src/main/java/ironhack/com/ReadCsvInfo.java b/Ironhack-school/src/main/java/ironhack/com/ReadCsvInfo.java
new file mode 100644
index 0000000..cdd8f83
--- /dev/null
+++ b/Ironhack-school/src/main/java/ironhack/com/ReadCsvInfo.java
@@ -0,0 +1,143 @@
+package ironhack.com;
+
+import java.io.*;
+import java.util.*;
+
+import static ironhack.com.Course.findCourseByName;
+
+public class ReadCsvInfo {
+ public static List global_course;
+ //TODO handling possible exceptions
+ public static String[] readSchoolInfo() throws FileNotFoundException {
+ String SCHOOL_PATH = "src/files/School.csv";
+ File file_school = new File(SCHOOL_PATH);
+ Scanner school_scanner =new Scanner(file_school);
+
+ school_scanner.nextLine();
+ String[] school_vector = school_scanner.nextLine().split(",");
+ return school_vector;
+ }
+ public static List readObjectInfo(String path, int rowsToRead, RoleType type, boolean totalRows) throws IOException {
+ File file = new File(path);
+ Scanner sc = new Scanner(file);
+ List objectList = new ArrayList<>();
+
+ if (totalRows){
+ rowsToRead =countLines(path)-1;
+ }
+
+ sc.nextLine();
+ for (int i = 1; i <= rowsToRead; i++) {
+ String[] properties = sc.nextLine().split(",");
+ ObjectType newObj = createInstance(type, properties);
+ if (newObj!=null) {
+ objectList.add(newObj);
+ }
+ }
+ return objectList;
+ }
+
+ public static ObjectType createInstance(RoleType type, String[] properties) {
+ switch (type) {
+ case TEACHER:
+ if (!Utils.validateName(properties[0])) {
+ System.out.println("Invalid teacher name: " + properties[0]);
+ return null;
+ }
+ @SuppressWarnings("unchecked")
+ ObjectType teacher = (ObjectType) new Teacher(properties[0], Double.parseDouble(properties[1]));
+ return teacher;
+ case STUDENT:
+
+ if (!Utils.validateName(properties[0]) || !Utils.ValidateEmail.isValidEmail(properties[2])) {
+ System.out.println("Invalid student name or email: " + properties[0] + ", " + properties[2]);
+ return null;
+ }
+ List courses_list= new ArrayList<>();
+ Course posible_course=null;
+ for (String course: parseCourseList(properties[3])){
+ if(!course.equals("") ){
+ posible_course = findCourseByName(global_course, course);
+ }
+ if (posible_course!=null){
+ courses_list.add(posible_course);
+ }
+ }
+ if (courses_list!=null){
+ @SuppressWarnings("unchecked")
+ ObjectType student = (ObjectType) new Student(properties[0], properties[1], properties[2],courses_list);
+ return student;
+ }else{
+ @SuppressWarnings("unchecked")
+ ObjectType student = (ObjectType) new Student(properties[0], properties[1], properties[2]);
+ return student;
+ }
+ case COURSE:
+ // if (!Utils.validateName(properties[0])) {
+ // System.out.println("Invalid course name: " + properties[0]);
+ // return null;
+ //}
+ @SuppressWarnings("unchecked")
+
+ ObjectType course = (ObjectType) new Course(properties[0], Double.parseDouble(properties[1]));
+ return course;
+ default:
+ throw new IllegalArgumentException("Invalid RoleType");
+ }
+ }
+ public static List parseCourseList(String courseListString) {
+ List courses = new ArrayList<>();
+
+ String trimmedString = courseListString.substring(1, courseListString.length() - 1);
+ String[] coursesArray = trimmedString.split("\\|");
+
+ for (String course : coursesArray) {
+ courses.add(course.trim());
+ }
+
+ return courses;
+ }
+ public static int countLines(String filePath) throws IOException {
+ int count = 0;
+ try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
+ while (br.readLine() != null) {
+ count++;
+ }
+ }
+ return count;
+ }
+ public static School school_creation_csv() {
+ School school = null;
+ try {
+ String[] school_info = readSchoolInfo();
+
+
+ List teachers = readObjectInfo("src/files/Teachers.csv",1,RoleType.TEACHER, true);
+ global_course = readObjectInfo("src/files/Courses.csv",2,RoleType.COURSE,true);
+ List students = readObjectInfo("src/files/Students.csv",2,RoleType.STUDENT,true);
+
+
+ school = new School(school_info[0]);
+ school.setListToStudentMap(students);
+ school.setListToTeacherMap(teachers);
+ school.setListToCourseMap(global_course);
+
+ System.out.println("All Courses");
+ school.showCourses();
+
+ System.out.println("All Teachers");
+ school.showTeachers();
+
+ System.out.println("All Students");
+ school.showStudents();
+ return school;
+ } catch (FileNotFoundException e) {
+ System.err.println("File not found: " + e.getMessage());
+ return school;
+ } catch (IOException e) {
+ System.err.println("problem with csv, skipped school creation");
+ return school;
+ }
+ }
+
+}
diff --git a/Ironhack-school/src/main/java/ironhack/com/RoleType.java b/Ironhack-school/src/main/java/ironhack/com/RoleType.java
new file mode 100644
index 0000000..2069c23
--- /dev/null
+++ b/Ironhack-school/src/main/java/ironhack/com/RoleType.java
@@ -0,0 +1,7 @@
+package ironhack.com;
+
+public enum RoleType {
+ TEACHER,
+ STUDENT,
+ COURSE
+}
diff --git a/Ironhack-school/src/main/java/ironhack/com/School.java b/Ironhack-school/src/main/java/ironhack/com/School.java
new file mode 100644
index 0000000..6e7417c
--- /dev/null
+++ b/Ironhack-school/src/main/java/ironhack/com/School.java
@@ -0,0 +1,233 @@
+package ironhack.com;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Getter
+@Setter
+public class School {
+ private String name;
+ private Map student_map = new HashMap<>();
+ private Map teacher_map = new HashMap<>();
+ private Map course_map = new HashMap<>();
+
+ public School(String name) {
+ if (name == null || name.isEmpty()) {
+ throw new IllegalArgumentException("Name cannot be null or empty.");
+ }
+ this.name = name;
+ }
+
+ public void showStudents() {
+ if (student_map.isEmpty()) {
+ System.out.println("No students found.");
+ } else {
+ student_map.forEach((id, student) -> {
+ student.printInfo();
+ });
+ }
+ }
+
+ public void lookupStudent(String studentId) {
+ Student student = student_map.get(studentId);
+ if (student != null) {
+ student.printInfo();
+ } else {
+ System.out.println("Student with ID " + studentId + " not found.");
+ }
+ }
+
+ public void setListToStudentMap(List students) {
+ if (students.isEmpty()) {
+ System.out.println("No students to add.");
+ } else {
+ Map students_map = new HashMap<>();
+ for (Student student : students) {
+ students_map.put(student.getId(), student);
+ }
+ setStudent_map(students_map);
+ }
+ }
+
+ public void setListToCourseMap(List courses) {
+ if (courses.isEmpty()) {
+ System.out.println("No courses to add.");
+ } else {
+ Map courses_map = new HashMap<>();
+ for (Course course : courses) {
+ courses_map.put(course.getId(), course);
+ }
+ setCourse_map(courses_map);
+ }
+ }
+
+ public void setListToTeacherMap(List teachers) {
+ if (teachers.isEmpty()) {
+ System.out.println("No teachers to add.");
+ } else {
+ Map teachers_map = new HashMap<>();
+ for (Teacher teacher : teachers) {
+ teachers_map.put(teacher.getId(), teacher);
+ }
+ setTeacher_map(teachers_map);
+ }
+ }
+
+ public void showCourses() {
+ if (course_map.isEmpty()) {
+ System.out.println("No courses found.");
+ } else {
+ course_map.forEach((id, course) -> {
+ course.printInfo();
+ });
+ }
+ }
+
+ public Course lookupCourse(String courseId) {
+ Course course = course_map.get(courseId);
+ if (course != null) {
+ course.printInfo();
+ } else {
+ System.out.println("Course with ID " + courseId + " not found.");
+ }
+ return course;
+ }
+
+ public void showTeachers() {
+ if (teacher_map.isEmpty()) {
+ System.out.println("No teachers found.");
+ } else {
+ teacher_map.forEach((id, teacher) -> {
+ teacher.printInfo();
+ });
+ }
+ }
+
+ public void lookupTeacher(String teacherId) {
+ Teacher teacher = teacher_map.get(teacherId);
+ if (teacher != null) {
+ teacher.printInfo();
+ } else {
+ System.out.println("Teacher with ID " + teacherId + " not found.");
+ }
+ }
+ public void showProfit(){
+ System.out.println("Current Total Profit:");
+ System.out.println(String.valueOf(calculateProfit())+"€");
+ }
+ public double calculateProfit() {
+ double profit = 0;
+ for (Course course : course_map.values()) {
+ if (course == null) {
+ continue;
+ }
+ profit += course.getMoney_earned();
+ }
+ for (Teacher teacher : teacher_map.values()) {
+ if (teacher == null) {
+ continue;
+ }
+ profit -= teacher.getSalary();
+ }
+ return profit;
+ }
+
+ public void enroll(Student student, Course course) {
+
+ if (student == null) {
+ // System.out.println("Student not found.");
+ return;
+ }
+
+ if (course == null) {
+ // System.out.println("Course not found.");
+ return;
+ }
+
+ student.enrollInCourse(course);
+ course.setMoney_earned(course.getMoney_earned() + course.getPrice());
+ }
+
+ public void assignTeacherToCourse(String teacherId, String courseId) {
+ if (!teacher_map.containsKey(teacherId)) {
+ System.out.println("Teacher with ID " + teacherId + " does not exist.");
+ return;
+ }
+ if (!course_map.containsKey(courseId)) {
+ System.out.println("Course with ID " + courseId + " does not exist.");
+ return;
+ }
+ course_map.get(courseId).setTeacher(teacher_map.get(teacherId));
+ Teacher teacher = teacher_map.get(teacherId);
+ Course course = course_map.get(courseId);
+ course.assign(teacher);
+ }
+
+ public Student findStudentById(String studentId) {
+ if (student_map.containsKey(studentId)) {
+ return student_map.get(studentId);
+ } else {
+ System.out.println("Student with ID " + studentId + " not found.");
+ return null;
+ }
+ }
+
+ public Course findCourseById(String courseId) {
+ if (course_map.containsKey(courseId)) {
+ return course_map.get(courseId);
+ } else {
+ System.out.println("Course with ID " + courseId + " not found.");
+ return null;
+ }
+ }
+
+ public Teacher findTeacherById(String teacherId) {
+ if (teacher_map.containsKey(teacherId)) {
+ return teacher_map.get(teacherId);
+ } else {
+ System.out.println("Teacher with ID " + teacherId + " not found.");
+ return null;
+ }
+ }
+
+
+ public List findStudentsByCourseId(String courseId) {
+ Course course = findCourseById(courseId);
+
+ if (course == null) {
+ throw new IllegalArgumentException("Course not found");
+ }
+
+ List enrolledStudents = new ArrayList<>();
+ for (Student st : student_map.values()) {
+ if (st.getCourseList().contains(course)) {
+ enrolledStudents.add(st);
+ }
+ }
+
+ return enrolledStudents;
+
+ }
+
+
+ public double findMoneySpentByStudent(String studentId) {
+ Student student = student_map.get(studentId);
+ double totalMoneySpent = 0.0;
+ if (student != null) {
+ List courses = student.getCourseList();
+ for (Course course : courses) {
+ totalMoneySpent += course.getPrice();
+ }
+ } else {
+ System.out.println("Student not found");
+ }
+ return totalMoneySpent;
+ }
+
+
+}
\ No newline at end of file
diff --git a/Ironhack-school/src/main/java/ironhack/com/Student.java b/Ironhack-school/src/main/java/ironhack/com/Student.java
new file mode 100644
index 0000000..82f2f15
--- /dev/null
+++ b/Ironhack-school/src/main/java/ironhack/com/Student.java
@@ -0,0 +1,51 @@
+package ironhack.com;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Getter
+@Setter
+public class Student extends Person {
+ private String address;
+ private String email;
+ private List courseList;
+
+ public Student(String name, String address, String email) {
+ super(name);
+ this.address = address;
+ this.setEmail(email);
+ courseList = new ArrayList<>();
+ }
+
+ public Student(String name, String address, String email, List courseList) {
+ super(name);
+ this.address = address;
+ this.setEmail(email);
+ this.courseList = courseList;
+ }
+
+ public void setEmail(String email) {
+ if (!Utils.ValidateEmail.isValidEmail(email)) {
+ throw new IllegalArgumentException("Invalid email format");
+ }
+ this.email = email;
+ }
+
+ public void printInfo() {
+ System.out.print("Id: " + getId()
+ + ", Name: " + getName()
+ + ", Address: " + getAddress()
+ + ", Email: " + getEmail()
+ + ", Courses: [");
+ for(Course course:getCourseList()){
+ System.out.print(course.getName()+" ");
+ };
+ System.out.println("]");
+ }
+
+ public void enrollInCourse(Course course) {
+ this.courseList.add(course);
+ }
+}
\ No newline at end of file
diff --git a/Ironhack-school/src/main/java/ironhack/com/Teacher.java b/Ironhack-school/src/main/java/ironhack/com/Teacher.java
new file mode 100644
index 0000000..c8e369b
--- /dev/null
+++ b/Ironhack-school/src/main/java/ironhack/com/Teacher.java
@@ -0,0 +1,29 @@
+package ironhack.com;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class Teacher extends Person {
+
+ private double salary;
+
+ public Teacher(String name, double salary) {
+ super(name);
+ setSalary(salary);
+ }
+
+ public void setSalary(double salary) {
+ if (Double.isNaN(salary)) {
+ System.err.println("The input for salary must be a number");
+ } else {
+ this.salary = salary;
+ }
+ }
+
+ public void printInfo() {
+ System.out.println("Id: " + getId()
+ + ", Name: " + getName()
+ + ", Salary: " + getSalary());
+ }
+}
\ No newline at end of file
diff --git a/Ironhack-school/src/main/java/ironhack/com/Utils.java b/Ironhack-school/src/main/java/ironhack/com/Utils.java
new file mode 100644
index 0000000..648053e
--- /dev/null
+++ b/Ironhack-school/src/main/java/ironhack/com/Utils.java
@@ -0,0 +1,143 @@
+package ironhack.com;
+
+
+import java.time.Instant;
+import java.util.Scanner;
+import java.util.UUID;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class Utils {
+
+
+ public static String generateSerialId() {
+ long timestamp = Instant.now().toEpochMilli() % 1000000; // Taking only last 6 digits
+ int hashCode = (int) (Math.random() * 10000); // Generating a random 4-digit number
+ return String.valueOf(timestamp) + String.valueOf(hashCode);
+
+ }
+
+ public static boolean validateName(String name) {
+ String regex = "^[A-Za-z\\s]+";
+ Pattern pattern = Pattern.compile(regex);
+ Matcher matcher = pattern.matcher(name);
+ return matcher.matches();
+ }
+
+ public static class ValidateEmail {
+
+ private static final Pattern EMAIL_PATTERN =
+ Pattern.compile("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]+$");
+
+ public static boolean isValidEmail(String email) {
+ if (email == null) {
+ return false;
+ }
+ return EMAIL_PATTERN.matcher(email).matches();
+ }
+ }
+
+ public static int validateNumberOf(Scanner scanner, int bigger_than) {
+ int attempts = 0;
+ int maxAttempts = 3;
+
+ while (attempts < maxAttempts) {
+ String number_string = scanner.nextLine();
+ try {
+ int number = Integer.parseInt(number_string);
+ if (number >= bigger_than) {
+ return number;
+ } else {
+ System.out.println("Enter a valid number");
+ }
+ } catch (NumberFormatException e) {
+ System.out.println("Enter a valid number");
+ }
+ attempts++;
+ }
+ System.out.println("Exceeded maximum attempts. Exiting.");
+ return 0;
+ }
+
+ public static long validateIdOf(Scanner scanner) {
+ int attempts = 0;
+ int maxAttempts = 3;
+
+ while (attempts < maxAttempts) {
+ String number_string = scanner.nextLine();
+ try {
+ long number = Long.parseLong(number_string);
+
+ return number;
+
+ } catch (NumberFormatException e) {
+ System.out.println("Enter a valid number");
+ }
+ attempts++;
+ }
+ System.out.println("Exceeded maximum attempts. Exiting.");
+ return 0;
+ }
+
+ public static double validateDoubleOf(Scanner scanner) {
+ int attempts = 0;
+ int maxAttempts = 3;
+
+ while (attempts < maxAttempts) {
+ String number_string = scanner.nextLine();
+ try {
+ Double number = Double.parseDouble(number_string);
+ if (number > 0) {
+ return number;
+ } else {
+ System.out.println("Enter a valid number ex 250.50");
+ }
+ } catch (NumberFormatException e) {
+ System.out.println("Enter a valid number");
+ }
+ attempts++;
+ }
+ System.out.println("Exceeded maximum attempts. Exiting.");
+ return 0;
+ }
+
+ public static String validateEmailOf(Scanner scanner) {
+ int attempts = 0;
+ int maxAttempts = 3;
+
+ while (attempts < maxAttempts) {
+ String email = scanner.nextLine();
+
+ if (!Utils.ValidateEmail.isValidEmail(email)) {
+ System.out.println("Enter a valid email@email.com");
+ } else {
+ return email;
+ }
+
+ attempts++;
+ }
+ System.out.println("Exceeded maximum attempts. Exiting.");
+ return "";
+ }
+
+ public static String validateNameOf(Scanner scanner){
+ int attempts = 0;
+ int maxAttempts = 3;
+
+ while (attempts < maxAttempts) {
+ String name=scanner.nextLine();
+
+ if(!Utils.validateName(name)){
+ System.out.println("Enter a valid name, only Letters allowed");
+ }
+ else{
+ return name;
+ }
+ attempts++;
+ }
+ System.out.println("Exceeded maximum attempts. Exiting.");
+ return "";
+ }
+
+
+}
diff --git a/Ironhack-school/src/test/java/ironhack/com/AppTest.java b/Ironhack-school/src/test/java/ironhack/com/AppTest.java
new file mode 100644
index 0000000..8478731
--- /dev/null
+++ b/Ironhack-school/src/test/java/ironhack/com/AppTest.java
@@ -0,0 +1,206 @@
+package ironhack.com;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.junit.jupiter.api.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+{
+
+ private Teacher teacher1;
+ private Teacher teacher2;
+ private List teachers;
+
+ private Course course1;
+ private Course course2;
+ private List courses;
+
+ private Student student1;
+ private Student student2;
+ private Student student3;
+ private List students;
+
+ private School school;
+
+ final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+ private final PrintStream outContentClean = System.out;
+
+ @BeforeEach
+ public void setUp() {
+ teacher1 = new Teacher("Maria",45000d);
+ teacher2 = new Teacher("Anna",45000d);
+ teachers = new ArrayList<>(List.of(teacher1,teacher2));
+
+ course1 = new Course("Java Backend", 4000d,teacher1);
+ course2 = new Course("Frontend", 4000d,teacher2);
+ courses = new ArrayList<>(List.of(course1,course2));
+
+ student1 = new Student("Paula","Calle Calabria 25","paulasg461@gmail.com");
+ student2 = new Student("Ariadna","Calle Paterna 86","ariadnamp_99@gmail.com");
+ student3 = new Student("Sandra","Calle Laurel 4","sandra_laurel52@gmail.com");
+ students = new ArrayList<>(List.of(student1,student2,student3));
+
+ school = new School("MiCasita");
+ school.setListToTeacherMap(teachers);
+ school.setListToCourseMap(courses);
+ school.setListToStudentMap(students);
+
+ System.setOut(new PrintStream(outContent));
+ }
+
+ @AfterEach
+ void outContentClean(){
+ System.setOut(outContentClean);
+ }
+// /**
+// * Create the test case
+// *
+// * @param testName name of the test case
+// */
+// public AppTest( String testName )
+// {
+// super( testName );
+// }
+
+// /**
+// * @return the suite of tests being tested
+// */
+// public static Test suite()
+// {
+// return new TestSuite( AppTest.class );
+// }
+
+// /**
+// * Rigourous Test :-)
+// */
+// public void testApp()
+// {
+// assertTrue( true );
+// }
+
+ @Test
+ public void testCreateObjects() {
+ assertEquals("Maria",teacher1.getName());
+ assertEquals(4000d,course1.getPrice());
+ assertEquals(teacher1,course1.getTeacher());
+ }
+
+ @Test
+ public void testCreateStudentWithNotValidEmail() {
+
+ String name = "Paula";
+ String address = "Calle Calabria 25";
+ assertThrows(IllegalArgumentException.class, () -> new Student(name, address, "paulasg461@gmail"),
+ "Expected IllegalArgumentException to be thrown");
+ assertThrows(IllegalArgumentException.class, () -> new Student(name, address, "paulasg461.com"),
+ "Expected IllegalArgumentException to be thrown");
+
+ assertThrows(IllegalArgumentException.class, () -> new Student(name, address, "dhjskjfsfsjfksefjicnweirmw"),
+ "Expected IllegalArgumentException to be thrown");
+ }
+
+ @Test
+ public void testCreateSchoolWithNotValidName() {
+ School schoolNotValidName = new School("&3");
+ // pending
+ }
+
+ @Test
+ public void testFillInSchool() {
+ // TeacherMap tests
+ assertEquals(2,school.getTeacher_map().size());
+ assertEquals(teacher1,school.getTeacher_map().get(teacher1.getId()));
+ assertEquals(teacher1.getSalary(),school.getTeacher_map().get(teacher1.getId()).getSalary());
+
+ // CourseMap tests
+ assertEquals(2,school.getCourse_map().size());
+ assertEquals(course2,school.getCourse_map().get(course2.getId()));
+ assertEquals(course2.getName(),school.getCourse_map().get(course2.getId()).getName());
+
+ // StudentMap tests
+ assertEquals(3,school.getStudent_map().size());
+ assertEquals(student1,school.getStudent_map().get(student1.getId()));
+ assertEquals(student1.getAddress(),school.getStudent_map().get(student1.getId()).getAddress());
+ }
+
+// @Test
+// public void testLookupMethods() {
+// assertEquals(teacher1,school.lookupTeacher(teachers.get(0).getId()));
+// assertEquals(course2,school.lookupCourse(courses.get(1).getId()));
+// assertEquals(student3,school.lookupStudent(students.get(2).getId()));
+// }
+
+// @Test
+// public void testShowInfoMethods() {
+// school.showCourses();
+// String out1 = ("Id: " + course1.getId()
+// + ", Name: " + course1.getName()
+// + ", Price: " + course1.getPrice()
+// + ", Money Earned: " + course1.getMoney_earned()
+// + ", Teacher: " +(course1.getTeacher() != null ? course1.getTeacher().getName() : "N/A"));
+//
+// String out2 = ("Id: " + course2.getId()
+// + ", Name: " + course2.getName()
+// + ", Price: " + course2.getPrice()
+// + ", Money Earned: " + course2.getMoney_earned()
+// + ", Teacher: " +(course2.getTeacher() != null ? course2.getTeacher().getName() : "N/A"));
+// assertEquals(out1 + "\n" + out2 + "\n", outContent.toString());
+//
+// }
+
+ @Test
+ public void testEnrollStudent() {
+ student1.enrollInCourse(course1);
+ assertEquals(1,student1.getCourseList().size());
+ assertEquals(course1.getName(), student1.getCourseList().get(0).getName());
+
+ student1.enrollInCourse(course2);
+ assertEquals(2,student1.getCourseList().size());
+ assertEquals(course2.getName(), student1.getCourseList().get(1).getName());
+ }
+ // pending test assigning a null course(?) and/or to a null student(?)
+
+ @Test
+ public void testAssignTeacher() {
+ //school.assignTeacherToCourse(teacher1.getId(),course1.getId());
+
+ course1.assign(teacher1);
+ assertEquals(teacher1,course1.getTeacher());
+ assertEquals(teacher1,school.getCourse_map().get(course1.getId()).getTeacher());
+ }
+ // pending test assigning a null teacher(?)
+
+ @Test
+ public void testShowProfit() {
+ double profitActual = school.calculateProfit();
+
+ double profitExpected = 0d;
+ // Sum up all money earned from all courses
+ Map schoolCourses = school.getCourse_map();
+ for (Map.Entry course : schoolCourses.entrySet()) {
+ profitExpected += course.getValue().getMoney_earned();
+ }
+ // Deduct all teachers' salaries
+ Map schoolTeachers = school.getTeacher_map();
+ for (Map.Entry teacher : schoolTeachers.entrySet()) {
+ profitExpected -= teacher.getValue().getSalary();
+ }
+
+ assertEquals(profitExpected,profitActual);
+ }
+}
\ No newline at end of file
diff --git a/Ironhack-school/src/test/java/ironhack/com/ReadCsvInfoTest.java b/Ironhack-school/src/test/java/ironhack/com/ReadCsvInfoTest.java
new file mode 100644
index 0000000..a224517
--- /dev/null
+++ b/Ironhack-school/src/test/java/ironhack/com/ReadCsvInfoTest.java
@@ -0,0 +1,71 @@
+package ironhack.com;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class ReadCsvInfoTest {
+
+ @Test
+ void createInstance_WithValidStudentData_ReturnsStudent() {
+ // Assumes input validation methods will pass.
+ String[] properties = {"Valid Name", "123 Main St", "email@example.com","[]"};
+
+ Student student = ReadCsvInfo.createInstance(RoleType.STUDENT, properties);
+
+ Assertions.assertNotNull(student, "Student should not be null for valid inputs");
+ Assertions.assertEquals("Valid Name", student.getName());
+ Assertions.assertEquals("email@example.com", student.getEmail());
+ }
+
+ @Test
+ void createInstance_WithInvalidStudentName_ReturnsNull() {
+ String[] properties = {"", "123 Main St", "email@example.com"};
+
+ Student student = ReadCsvInfo.createInstance(RoleType.STUDENT, properties);
+
+ Assertions.assertNull(student, "Student should be null for invalid name input");
+ }
+
+ @Test
+ void createInstance_WithInvalidStudentEmail_ReturnsNull() {
+ String[] properties = {"Valid Name", "123 Main St", "not an email"};
+
+ Student student = ReadCsvInfo.createInstance(RoleType.STUDENT, properties);
+
+ Assertions.assertNull(student, "Student should be null for invalid email input");
+ }
+
+ @Test
+ void createInstance_WithValidTeacherData_ReturnsTeacher() {
+ String[] properties = {"Valid Teacher", "5000.50"};
+ Teacher teacher = ReadCsvInfo.createInstance(RoleType.TEACHER, properties);
+
+ Assertions.assertNotNull(teacher, "Teacher should not be null for valid inputs");
+ Assertions.assertEquals("Valid Teacher", teacher.getName());
+ }
+
+ @Test
+ void createInstance_WithInvalidTeacherName_ReturnsNull() {
+ String[] properties = {"", "5000.50"};
+ Teacher teacher = ReadCsvInfo.createInstance(RoleType.TEACHER, properties);
+
+ Assertions.assertNull(teacher, "Teacher should be null for invalid name input");
+ }
+
+ @Test
+ void createInstance_WithValidCourseData_ReturnsCourse() {
+ String[] properties = {"Valid Course", "3"};
+ Course course = ReadCsvInfo.createInstance(RoleType.COURSE, properties);
+
+ Assertions.assertNotNull(course, "Course should not be null for valid inputs");
+ Assertions.assertEquals("Valid Course", course.getName());
+ }
+
+// @Test
+// void createInstance_WithInvalidCourseName_ReturnsNull() {
+// String[] properties = {"", "3"};
+// Course course = ReadCsvInfo.createInstance(RoleType.COURSE, properties);
+//
+// Assertions.assertNull(course, "Course should be null for invalid name input");
+// }
+}
diff --git a/Ironhack-school/src/test/java/ironhack/com/SchoolTest.java b/Ironhack-school/src/test/java/ironhack/com/SchoolTest.java
new file mode 100644
index 0000000..5c40699
--- /dev/null
+++ b/Ironhack-school/src/test/java/ironhack/com/SchoolTest.java
@@ -0,0 +1,269 @@
+package ironhack.com;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import static org.junit.jupiter.api.Assertions.*;
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class SchoolTest {
+
+ // Create a school
+ School school = new School("Test School");
+
+ Course course1 = new Course("Course1", 1000.0);
+ Course course2 = new Course("Course2", 2000.0);
+ Teacher teacher1 = new Teacher("Teacher1", 500.0);
+ Teacher teacher2 = new Teacher("Teacher2", 1000.0);
+ Student student1 = new Student("Student1", "Address1", "student1@example.com");
+ Student student2 = new Student("Student2", "Address2", "student2@example.com");
+
+ @BeforeEach
+ void setUp() {
+ // Create some courses and teachers and add them to the school
+ school.getCourse_map().put(course1.getId(), course1);
+ school.getCourse_map().put(course2.getId(), course2);
+ school.getTeacher_map().put(teacher1.getId(), teacher1);
+ school.getTeacher_map().put(teacher2.getId(), teacher2);
+
+ // Create some students and enroll them in the courses
+ school.getStudent_map().put(student1.getId(), student1);
+ school.getStudent_map().put(student2.getId(), student2);
+
+ school.enroll(student1, course1);
+ school.enroll(student2, course2);
+ }
+
+
+@Test
+public void testCalculateProfit() {
+ // Calculate the profit
+ double profit = school.calculateProfit();
+
+ // Check if the profit is as expected
+ assertEquals(1500.0, profit);
+}
+
+ @Test
+ public void testFindMoneySpentByStudent() {
+ double moneySpent = school.findMoneySpentByStudent(student1.getId());
+ assertEquals(1000.0, moneySpent);
+ }
+
+ @Test
+ public void testFindStudentsByCourseId() {
+ List students = school.findStudentsByCourseId(course1.getId());
+ assertEquals(1, students.size());
+ }
+
+ @Test
+ public void testEnroll() {
+ school.enroll(student1, course1);
+ Course courseEnrolled = school.getStudent_map().get(student1.getId()).getCourseList().get(0);
+ assertEquals("Course1", courseEnrolled.getName());
+ }
+
+@Test
+public void testLookupTeacher() {
+ // Create a school
+ School school = new School("Test School");
+
+ // Create a teacher and add it to the school
+ Teacher teacher1 = new Teacher("Teacher1", 500.0);
+ school.getTeacher_map().put(teacher1.getId(), teacher1);
+
+ // Use the lookupTeacher method to find the teacher
+ school.lookupTeacher(teacher1.getId());
+
+ assertTrue(school.getTeacher_map().containsKey(teacher1.getId()));
+}
+
+@Test
+public void testShowTeachers() {
+ // Create a school
+ School school = new School("Test School");
+
+ // Create a teacher and add it to the school
+ Teacher teacher1 = new Teacher("Teacher1", 500.0);
+ school.getTeacher_map().put(teacher1.getId(), teacher1);
+
+ // Use the showTeachers method
+ school.showTeachers();
+
+ assertFalse(school.getTeacher_map().isEmpty());
+}
+
+@Test
+public void testLookupCourse() {
+ // Create a school
+ School school = new School("Test School");
+
+ // Create a course and add it to the school
+ Course course1 = new Course("Course1", 1000.0);
+ school.getCourse_map().put(course1.getId(), course1);
+
+ // Use the lookupCourse method
+ school.lookupCourse(course1.getId());
+
+ assertTrue(school.getCourse_map().containsKey(course1.getId()));
+}
+
+@Test
+public void testShowCourses() {
+ // Create a school
+ School school = new School("Test School");
+
+ // Create a course and add it to the school
+ Course course1 = new Course("Course1", 1000.0);
+ school.getCourse_map().put(course1.getId(), course1);
+
+ // Use the showCourses method
+ school.showCourses();
+
+
+ assertFalse(school.getCourse_map().isEmpty());
+}
+
+@Test
+public void testSetListToTeacherMap() {
+ // Create a school
+ School school = new School("Test School");
+
+ // Create a list of teachers and add it to the school
+ List teachers = new ArrayList<>();
+ Teacher teacher1 = new Teacher("Teacher1", 500.0);
+ teachers.add(teacher1);
+
+ // Use the setListToTeacherMap method
+ school.setListToTeacherMap(teachers);
+
+ assertFalse(school.getTeacher_map().isEmpty());
+}
+
+@Test
+public void testSetListToCourseMap() {
+ // Create a school
+ School school = new School("Test School");
+
+ // Create a list of courses and add it to the school
+ List courses = new ArrayList<>();
+ Course course1 = new Course("Course1", 1000.0);
+ courses.add(course1);
+
+ // Use the setListToCourseMap method
+ school.setListToCourseMap(courses);
+
+ assertFalse(school.getCourse_map().isEmpty());
+}
+
+@Test
+public void testSetListToStudentMap() {
+ // Create a school
+ School school = new School("Test School");
+
+ // Create a list of students and add it to the school
+ List students = new ArrayList<>();
+ Student student1 = new Student("Student1", "Address1", "student1@example.com");
+ students.add(student1);
+
+ // Use the setListToStudentMap method
+ school.setListToStudentMap(students);
+
+ assertFalse(school.getStudent_map().isEmpty());
+}
+
+@Test
+public void testLookupStudent() {
+ // Create a school
+ School school = new School("Test School");
+
+ // Create a student and add it to the school
+ Student student1 = new Student("Student1", "Address1", "student1@example.com");
+ school.getStudent_map().put(student1.getId(), student1);
+
+ // Use the lookupStudent method
+ school.lookupStudent(student1.getId());
+
+ assertTrue(school.getStudent_map().containsKey(student1.getId()));
+}
+
+@Test
+public void testShowStudents() {
+ // Create a school
+ School school = new School("Test School");
+
+ // Create a student and add it to the school
+ Student student1 = new Student("Student1", "Address1", "student1@example.com");
+ school.getStudent_map().put(student1.getId(), student1);
+
+ // Use the showStudents method
+ school.showStudents();
+
+ assertFalse(school.getStudent_map().isEmpty());
+}
+
+@Test
+public void testSchoolConstructor() {
+ // Create a school
+ School school = new School("Test School");
+
+ // Verify that the name is set correctly
+ assertEquals("Test School", school.getName());
+}
+
+@Test
+public void testFindStudentById() {
+ // Create a school
+ School school = new School("Test School");
+
+ // Create a student and add it to the school
+ Student student1 = new Student("Student1", "Address1", "student1@example.com");
+ school.getStudent_map().put(student1.getId(), student1);
+
+ // Use the findStudentById method
+ Student foundStudent = school.findStudentById(student1.getId());
+
+ // Verify that the correct student is returned
+ assertEquals(student1, foundStudent);
+}
+
+@Test
+public void testFindCourseById() {
+ // Create a school
+ School school = new School("Test School");
+
+ // Create a course and add it to the school
+ Course course1 = new Course("Course1", 1000.0);
+ school.getCourse_map().put(course1.getId(), course1);
+
+ // Use the findCourseById method
+ Course foundCourse = school.findCourseById(course1.getId());
+
+ // Verify that the correct course is returned
+ assertEquals(course1, foundCourse);
+}
+
+@Test
+public void testFindTeacherById() {
+ // Create a school
+ School school = new School("Test School");
+
+ // Create a teacher and add it to the school
+ Teacher teacher1 = new Teacher("Teacher1", 500.0);
+ school.getTeacher_map().put(teacher1.getId(), teacher1);
+
+ // Use the findTeacherById method
+ Teacher foundTeacher = school.findTeacherById(teacher1.getId());
+
+ // Verify that the correct teacher is returned
+ assertEquals(teacher1, foundTeacher);
+}
+
+}