diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..f0d9157
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..aa00ffa
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/homework-java-ironschool.iml b/.idea/homework-java-ironschool.iml
new file mode 100644
index 0000000..abe781f
--- /dev/null
+++ b/.idea/homework-java-ironschool.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..712ab9d
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..5d6b03c
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ 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/README_IS.md b/README_IS.md
new file mode 100644
index 0000000..48e2de8
--- /dev/null
+++ b/README_IS.md
@@ -0,0 +1,29 @@
+# School Management System
+
+This project is a School Management System that helps manage students, teachers, and courses with basic functionalities. It includes classes for Teacher, Student, and Course, along with a text-based menu system to interact with the system.
+
+## How the Application Works
+
+The application starts by asking for the school's name. Then, it asks for the teachers, students and courses to be created and their details.
+
+Once the school has been created, the user can enter commands to execute actions in the system.
+
+## Commands
+
+- **ENROLL [STUDENT_ID] [COURSE_ID]**: Enrolls the specified student in the corresponding course and updates the course's money_earned.
+- **ASSIGN [TEACHER_ID] [COURSE_ID]**: Assigns the specified teacher to the corresponding course.
+- **SHOW COURSES**: Displays a list of all courses.
+- **LOOKUP COURSE [COURSE_ID]**: Displays the full details of the specified course.
+- **SHOW STUDENTS**: Displays a list of all students.
+- **LOOKUP STUDENT [STUDENT_ID]**: Displays the full details of the specified student.
+- **SHOW TEACHERS**: Displays a list of all teachers.
+- **LOOKUP TEACHER [TEACHER_ID]**: Displays the full details of the specified teacher.
+- **SHOW PROFIT**: Calculates and displays the total profit (money earned from courses - sum of all teachers' salaries).
+- **ADD NEW TEACHER**
+- **ADD NEW COURSE**
+- **ADD NEW STUDENT**
+
+## Testing
+
+In order to ensure the reliability and functionality of the system's main features and commands, a comprehensive testing approach has been implemented.
+This includes the creation of unit tests using JUnit, these tests cover various scenarios and edge cases to validate the behavior of the system under different conditions.
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..8130d44
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,25 @@
+
+
+ 4.0.0
+
+ groupId
+ homework-java-ironschool
+ 1.0-SNAPSHOT
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.10.0
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/org/Command.java b/src/main/java/org/Command.java
new file mode 100644
index 0000000..61168a6
--- /dev/null
+++ b/src/main/java/org/Command.java
@@ -0,0 +1,169 @@
+package org;
+
+
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import static org.PrintUtils.printBlue;
+
+public class Command {
+
+ public static void displayCommands(){
+ System.out.println(printBlue("Please, select a command from the menu:\n"));
+ System.out.println("1. Enroll a new student");
+ System.out.println("2. Assign teacher to a course");
+ System.out.println("3. See all courses");
+ System.out.println("4. Search for a specific course");
+ System.out.println("5. See all students");
+ System.out.println("6. Search for a specific student");
+ System.out.println("7. See all teachers");
+ System.out.println("8. Search for a specific teacher");
+ System.out.println("9. Show profit");
+ System.out.println("10. Add new course");
+ System.out.println("11. Add new student");
+ System.out.println("12. Add new teacher");
+ System.out.println("13. Remove teacher from course");
+ System.out.println("14. Unroll student from course");
+ System.out.println("15. Enroll a list of students to course");
+ System.out.println("16. Exit program \n");
+ System.out.print(printBlue("Enter your choice: "));
+ }
+
+ public static void enrollStudent(String studentId, String courseId, School school) {
+ // Gets student by looking through students map
+ Student student = CommandUtils.getStudentById(school.getStudentMap(), studentId);
+ // Gets course by looking through courses map
+ Course course = CommandUtils.getCourseById(school.getCourseMap(), courseId);
+
+ // Checks if the course and the student exist
+ if (student != null && course != null) {
+ // Check if the student is already enrolled in another course
+ //**************mas cambios lista courses
+ if (student.getCourse() != null) {
+ throw new IllegalArgumentException("Student is already enrolled in a course.");
+ }
+
+
+
+ // Enrolls student in the course
+ student.setCourse(course);
+
+
+ // Updates money earned in the course based on its price
+ course.updateMoney_earned(course.getMoney_earned() + course.getPrice());
+ } else {
+ throw new IllegalArgumentException("Invalid student or course ID.");
+ }
+ }
+
+
+ public static void assignTeacher(String teacherId, String courseId, School school){
+ //find course by id, getCourseMap()
+ Course course = CommandUtils.getCourseById(school.getCourseMap(), courseId);
+
+ if(course == null){
+ throw new IllegalArgumentException("Course doesn't exist!");
+ }
+
+ //find teacher by teacher id, getTeacherMap()
+ Teacher teacher = CommandUtils.getTeacherById(school.getTeacherMap(), teacherId);
+
+ if(teacher == null){
+ throw new IllegalArgumentException("Teacher doesn't exist!");
+ }
+ course.setTeacher(teacher);
+ }
+
+
+
+ public static void removeTeacherFromCourse(String courseId, School school){
+ //find course by id, getCourseMap()
+ Course course = CommandUtils.getCourseById(school.getCourseMap(), courseId);
+
+ if(course == null){
+ throw new IllegalArgumentException("Course doesn't exist!");
+ } else if (course.getTeacher() == null){
+ throw new IllegalArgumentException("No teacher assigned to this course!");
+ }
+
+ else {
+ course.removeTeacher();
+ }
+ }
+ public static void unenrollStudent(String studentId, String courseId, School school){
+ // Gets student by looking through students map
+ Student student = CommandUtils.getStudentById(school.getStudentMap(), studentId);
+ // Gets course by looking through courses map
+ Course course = CommandUtils.getCourseById(school.getCourseMap(), courseId);
+ // Checks if the course and the student exist
+ if (student != null && course != null) {
+ // Check if the student is enrolled in the given course
+ if (isStudentEnrolledInCourse(student, courseId)) {
+ // Remove the course from the student
+ student.removeCourse();
+
+ // Update money earned in the course based on its price
+ course.updateMoney_earned(course.getMoney_earned() - course.getPrice());
+ } else {
+ throw new IllegalArgumentException("Student is not enrolled in this course.");
+ }
+ } else {
+ throw new IllegalArgumentException("Invalid student or course ID.");
+ }
+ }
+
+ // Helper method to check if a student is enrolled in a given course
+ public static boolean isStudentEnrolledInCourse(Student student, String courseId) {
+ Course course = student.getCourse();
+ if (course != null && Objects.equals(course.getCourseId(), courseId)) {
+ return true;
+ } else {
+ return false;
+ }
+
+ }
+
+
+ public static void enrollStudents(List studentsIds, String courseId, School school) {
+ Course course = CommandUtils.getCourseById(school.getCourseMap(), courseId);
+ for(String id : studentsIds){
+ Student student = CommandUtils.getStudentById(school.getStudentMap(), id);
+ // Checks if the course and the student exist
+ if (student != null && course != null) {
+ //no comprobar si uno ya está matriculado, se vuelve a matricular
+
+ // Enrolls student in the course
+ student.setCourse(course);
+
+ // Updates money earned in the course based on its price
+ course.updateMoney_earned(course.getMoney_earned() + course.getPrice());
+ } else {
+ throw new IllegalArgumentException("Invalid student or course ID.");
+ }
+ }
+
+ }
+
+ public static double showProfit(School school) throws IllegalArgumentException {
+ double totalMoneyEarned = 0;
+ double totalTeacherSalaries = 0;
+
+ try {
+ // Calculate total money earned from all courses
+ for (Course course : school.getCourseMap().values()) {
+ totalMoneyEarned += course.getMoney_earned();
+ }
+
+ // Calculate the sum of all the teachers' salaries
+ for (Teacher teacher : school.getTeacherMap().values()) {
+ totalTeacherSalaries += teacher.getSalary();
+ }
+
+ // Return the result (difference)
+ return totalMoneyEarned - totalTeacherSalaries;
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("An error occurred while calculating profit: " + e.getMessage());
+ }
+ }
+}
diff --git a/src/main/java/org/CommandAddNewItem.java b/src/main/java/org/CommandAddNewItem.java
new file mode 100644
index 0000000..9bd1567
--- /dev/null
+++ b/src/main/java/org/CommandAddNewItem.java
@@ -0,0 +1,72 @@
+package org;
+
+import java.util.InputMismatchException;
+import java.util.Scanner;
+
+import static org.PrintUtils.printBlue;
+
+
+public class CommandAddNewItem {
+ public static void addNewTeacher (School school){
+ boolean is_num = false;
+ String name = "";
+ double salary = 00.00;
+ Scanner scanner = new Scanner(System.in);
+
+ System.out.println(printBlue("Enter teacher name:"));
+ name = scanner.nextLine();
+ System.out.println(printBlue("Enter teacher salary:"));
+ while (!is_num) {
+ try {
+ salary = scanner.nextDouble();
+ scanner.nextLine();
+ is_num = true;
+ } catch (InputMismatchException ie) {
+ scanner.nextLine();
+ System.err.println("Oops! You need to enter a number.");
+ }
+ }
+ Teacher teacher = new Teacher(name, salary);
+ school.getTeacherMap().put(teacher.getTeacherId(), teacher);
+ }
+
+ public static void addNewCourse(School school){
+ boolean is_num = false;
+ String name = "";
+ double price = 00.00;
+ Scanner scanner = new Scanner(System.in);
+
+ System.out.println(printBlue("Enter course name:"));
+ name = scanner.nextLine();
+ System.out.println(printBlue("Enter course price:"));
+ while (!is_num) {
+ try {
+ price = scanner.nextDouble();
+ scanner.nextLine();
+ is_num = true;
+ } catch (InputMismatchException ie) {
+ scanner.nextLine();
+ System.err.println("Oops! You need to enter a number.");
+ }
+ }
+ Course course = new Course(name, price, (double) 0);
+ school.getCourseMap().put(course.getCourseId(), course);
+ }
+
+ public static void addNewStudent(School school){
+ String name = "";
+ String address = "";
+ String email = "";
+ Scanner scanner = new Scanner(System.in);
+
+ System.out.println(printBlue("Enter student name:"));
+ name = scanner.nextLine();
+ System.out.println(printBlue("Enter student address:"));
+ address = scanner.nextLine();
+ System.out.println(printBlue("Enter student email:"));
+ email = scanner.nextLine();
+
+ Student student = new Student(name, address, email);
+ school.getStudentMap().put(student.getStudentId(), student);
+ }
+}
diff --git a/src/main/java/org/CommandUtils.java b/src/main/java/org/CommandUtils.java
new file mode 100644
index 0000000..e198343
--- /dev/null
+++ b/src/main/java/org/CommandUtils.java
@@ -0,0 +1,174 @@
+package org;
+
+
+import java.util.*;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+
+public class CommandUtils {
+
+ public static void showAllTeachers(HashMap map){
+ System.out.println(printHeaderTableTeacher());
+ System.out.println(printRowSeparatorTeacher());
+ int entryIndex = 0;
+ for (Map.Entry entry : map.entrySet()) {
+ Teacher teacher = entry.getValue();
+ System.out.println("│" + teacher.getInfo() + "│");
+ if (++entryIndex < map.size()) {
+ System.out.println(printRowSeparatorTeacher());
+ } else {
+ System.out.println(printFooterTableTeacher());
+ }
+
+ }
+ }
+
+// public static void showStudentCourses(String studentId, School school){
+// Student student = getStudentById(school.getStudentMap(), studentId);
+//
+// if(student == null){
+// throw new IllegalArgumentException("Student doesn't exist!");
+// }
+// List courses = student.getCourse();
+// for(Course course : courses){
+// System.out.println(course.getInfo());
+// }
+// }
+
+
+
+
+
+
+
+
+ public static void showAllCourses(HashMap map){
+ System.out.println(printHeaderTableCourse());
+ System.out.println(printRowSeparatorCourse());
+ int entryIndex = 0;
+ for (Map.Entry entry : map.entrySet()) {
+ Course course = entry.getValue();
+ System.out.println("│" + course.getInfo() + "│");
+ if (++entryIndex < map.size()) {
+ System.out.println(printRowSeparatorCourse());
+ } else {
+ System.out.println(printFooterTableCourse());
+ }
+ }
+ }
+
+ public static void showAllStudents(HashMap map){
+ System.out.println(printHeaderTableStudent());
+ System.out.println(printRowSeparatorStudent());
+ int entryIndex = 0;
+ for (Map.Entry entry : map.entrySet()) {
+ Student student = entry.getValue();
+ System.out.println("│" + student.getInfo() + "│");
+ if (++entryIndex < map.size()) {
+ System.out.println(printRowSeparatorStudent());
+ } else {
+ System.out.println(printFooterTableStudent());
+ }
+ }
+ }
+
+ public static void lookUpTeacher(HashMap map, String targetId){
+ Teacher teacher = getTeacherById(map, targetId);
+ if (teacher != null){
+ System.out.println(printHeaderTableTeacher());
+ System.out.println(printRowSeparatorTeacher());
+ System.out.println("│" + teacher.getInfo() + "│");
+ System.out.println(printFooterTableTeacher());
+ }
+ }
+
+ public static void lookUpCourse(HashMap map, String targetId){
+ Course course = getCourseById(map, targetId);
+ if (course != null){
+ System.out.println(printHeaderTableCourse());
+ System.out.println(printRowSeparatorCourse());
+ System.out.println("│" + course.getInfo() + "│");
+ System.out.println(printFooterTableCourse());
+ }
+ }
+
+ public static void lookUpStudent(HashMap map, String targetId){
+ Student student = getStudentById(map, targetId);
+ if (student != null){
+ System.out.println(printHeaderTableStudent());
+ System.out.println(printRowSeparatorStudent());
+ System.out.println("│" + student.getInfo() + "│");
+ System.out.println(printFooterTableStudent());
+ }
+ }
+
+ public static Teacher getTeacherById(HashMap map, String targetId){
+ Teacher teacher = map.get(targetId);
+ if (teacher == null){
+ throw new IllegalArgumentException("Invalid teacher ID");
+ }
+ return teacher;
+ }
+
+ public static Course getCourseById(HashMap map, String targetId){
+ Course course = map.get(targetId);
+ if (course == null){
+ throw new IllegalArgumentException("Invalid course ID");
+ }
+ return course;
+ }
+
+ public static Student getStudentById(HashMap map, String targetId){
+ Student student = map.get(targetId);
+ if (student == null){
+ throw new IllegalArgumentException("Invalid student ID");
+ }
+ return student;
+ }
+
+ public static String printHeaderTableTeacher() {
+ return "┌─────┬───────────────────┬──────────────┐\n" +
+ "│ ID │ Name │ Salary │";
+ }
+
+ public static String printRowSeparatorTeacher() {
+
+ return "├─────┼───────────────────┼──────────────┤";
+ }
+
+ public static String printFooterTableTeacher() {
+ return "└─────┴───────────────────┴──────────────┘\n";
+ }
+
+ public static String printHeaderTableCourse() {
+ return "┌─────┬───────────────────┬──────────────┬───────────────────┐\n" +
+ "│ ID │ Name │ Price │ Teacher │";
+ }
+
+ public static String printRowSeparatorCourse() {
+
+ return "├─────┼───────────────────┼──────────────┼───────────────────┤";
+ }
+
+ public static String printFooterTableCourse() {
+ return "└─────┴───────────────────┴──────────────┴───────────────────┘\n";
+ }
+
+
+ public static String printHeaderTableStudent() {
+ return "┌─────┬────────────────────┬────────────────────┬────────────────────┬────────────────────┐\n" +
+ "│ ID │ Name │ Address │ Email │ Course │";
+ }
+ public static String printRowSeparatorStudent() {
+
+ return "├─────┼────────────────────┼────────────────────┼────────────────────┼────────────────────┤";
+ }
+
+ public static String printFooterTableStudent() {
+ return "└─────┴────────────────────┴────────────────────┴────────────────────┴────────────────────┘\n";
+ }
+}
diff --git a/src/main/java/org/Commands.java b/src/main/java/org/Commands.java
new file mode 100644
index 0000000..c943db1
--- /dev/null
+++ b/src/main/java/org/Commands.java
@@ -0,0 +1,273 @@
+package org;
+
+import java.util.ArrayList;
+import java.util.InputMismatchException;
+import java.util.List;
+import java.util.Scanner;
+
+import static org.Command.*;
+import static org.Command.showProfit;
+import static org.CommandAddNewItem.*;
+import static org.CommandUtils.*;
+import static org.PrintUtils.*;
+import static org.PrintUtils.printYellow;
+
+public class Commands {
+
+ public static void menuCommands (School school){
+ Scanner scanner = new Scanner(System.in);
+ int choiceMenu;
+ do{
+
+ displayCommands();
+ choiceMenu = scanner.nextInt();
+ String studentId;
+ String courseId;
+ String teacherId;
+
+ switch(choiceMenu){
+ case 1:
+
+ System.out.println("These are all the students that join "+ printPurple(school.getName())+" school:");
+ showAllStudents(school.getStudentMap());
+
+ System.out.println(printBlue("Enter the id of the student:"));
+ scanner.nextLine();
+ studentId = scanner.nextLine();
+ System.out.println("\nThese are all the courses available: ");
+ showAllCourses(school.getCourseMap());
+
+ System.out.println(printBlue("\nEnter the id of the course:"));
+ courseId = scanner.nextLine();
+ System.out.println(printBlueBold("Please wait, enrolling student...\n \n"));
+
+ try{
+ enrollStudent(studentId, courseId, school);
+ System.out.println(printYellow("Congratulations! Your student has been successfully enrolled to the course:\n"));
+ }catch(IllegalArgumentException e){
+ System.out.println(printRed("Error: "+e.getMessage()));
+ }
+
+ break;
+ case 2:
+ System.out.println("These are all the teachers that work for "+printPurple(school.getName())+" school:");
+ showAllTeachers(school.getTeacherMap());
+
+ System.out.println(printBlue("\n Enter the id of the teacher:"));
+ scanner.nextLine();
+ teacherId = scanner.nextLine();
+
+ System.out.println("\n These are all the courses available");
+ showAllCourses(school.getCourseMap());
+ System.out.println(printBlue("\n Enter the id of the course:"));
+ courseId = scanner.nextLine();
+ System.out.println(printBlueBold("Please wait, assigning teacher to the course... \n \n"));
+ try{
+ assignTeacher(teacherId, courseId, school);
+ System.out.println(printYellow("Congratulations! Your teacher has been successfully assigned to the course."));
+
+ }catch(IllegalArgumentException e){
+ System.out.println("Error: "+e.getMessage());
+ }
+
+ break;
+ case 3:
+ try{
+ System.out.println("\n These are all the courses available:");
+ showAllCourses(school.getCourseMap());
+
+ }catch(IllegalArgumentException e){
+ System.out.println(printRed("Error: "+e.getMessage()));
+ }
+ break;
+ case 4:
+ System.out.println(printBlue("Enter the id of the course:"));
+ scanner.nextLine();
+ courseId = scanner.nextLine();
+
+ try{
+ lookUpCourse(school.getCourseMap(),courseId);
+ }catch(IllegalArgumentException e){
+ System.out.println("Error: "+e.getMessage());
+ }
+ break;
+ case 5:
+ try{
+ System.out.println("These are all the students enrolled:");
+ showAllStudents(school.getStudentMap());
+ System.out.println("");
+ System.out.println("");
+ }catch(IllegalArgumentException e){
+ System.out.println("Error: "+e.getMessage());
+ }
+ break;
+ case 6:
+ System.out.println(printBlue("Enter the id of the student:"));
+ scanner.nextLine();
+ studentId = scanner.nextLine();
+
+ try{
+ lookUpStudent(school.getStudentMap(),studentId);
+ }catch(IllegalArgumentException e){
+ System.out.println("Error: "+e.getMessage());
+ }
+ break;
+ case 7:
+ try{
+ System.out.println("These are all the teachers that work at the school:");
+ showAllTeachers(school.getTeacherMap());
+ System.out.println("");
+ System.out.println("");
+ }catch(IllegalArgumentException e){
+ System.out.println("Error: "+e.getMessage());
+ }
+ break;
+ case 8:
+ System.out.println(printBlue("Enter the id of the teacher:"));
+ scanner.nextLine();
+ teacherId = scanner.nextLine();
+
+ try{
+ lookUpTeacher(school.getTeacherMap(), teacherId);
+ }catch(IllegalArgumentException e){
+ System.out.println("Error: "+e.getMessage());
+ }
+ break;
+ case 9:
+ double profit = showProfit(school);
+ System.out.println(printYellow("The profit of the school is ") + printPurple(String.valueOf(profit))+"\n");
+ break;
+ case 10:
+ addNewCourse(school);
+ break;
+ case 11:
+ addNewStudent(school);
+ break;
+ case 12:
+ addNewTeacher(school);
+ break;
+ case 13:
+ System.out.println("These are all the courses available");
+ showAllCourses(school.getCourseMap());
+ System.out.println("");
+ System.out.println(printBlue("Enter the id of the course:"));
+ scanner.nextLine();
+ courseId = scanner.nextLine();
+ System.out.println("Please wait, removing teacher from course.");
+ System.out.println("");
+ System.out.println("");
+ try{
+ Course course = CommandUtils.getCourseById(school.getCourseMap(), courseId);
+ String printTeacher = (course != null && course.getTeacher() != null)
+ ? course.getTeacher().getName()
+ : null;
+
+ removeTeacherFromCourse(courseId, school);
+
+ System.out.println(printYellow("Congratulations! "
+ + printTeacher
+ + " has been successfully removed from "
+ + CommandUtils.getCourseById(school.getCourseMap(), courseId).getName() + "."));
+
+ }catch(IllegalArgumentException e){
+ System.out.println("Error: "+e.getMessage());
+ }
+ break;
+ case 14:
+ System.out.println("These are all the students that join "+school.getName()+" school.");
+ showAllStudents(school.getStudentMap());
+ System.out.println("");
+ System.out.println(printBlue("Enter the id of the student:"));
+ scanner.nextLine();
+
+ studentId = scanner.next();
+ System.out.println("");
+
+ try{
+ System.out.println("These are all the courses available:");
+ showAllCourses(school.getCourseMap());
+ System.out.println("");
+ System.out.println(printBlue("Enter the id of the course:"));
+ scanner.nextLine();
+ courseId = scanner.nextLine();
+ System.out.println("Please wait, removing student from course.");
+ System.out.println("");
+ System.out.println("");
+ Student student = getStudentById(school.getStudentMap(), studentId);
+ Course course = getCourseById(school.getCourseMap(), courseId);
+ String printStudent = (course != null && student != null)
+ ? student.getName()
+ : null;
+ unenrollStudent(studentId, courseId, school);
+ System.out.println(printYellow("Congratulations! "
+ + printPurple(printStudent)
+ + " has been successfully unrolled from "
+ + printPurple(getCourseById(school.getCourseMap(), courseId).getName() + ".")));
+ }catch(IllegalArgumentException e){
+ System.out.println(printRed("Error: "+e.getMessage()));
+ }
+ break;
+ case 15:
+ System.out.println("These are all the students that join "+printPurple(school.getName())+" school.");
+ showAllStudents(school.getStudentMap());
+ System.out.println("");
+
+ int numberStudents = 0;
+ int maxStudents = school.getStudentMap().size();
+
+ while (true) {
+ try {
+ System.out.println(printBlue("How many students do you want to add?"));
+ numberStudents = scanner.nextInt();
+
+ if (numberStudents > 0 && numberStudents <= maxStudents) {
+ scanner.nextLine();
+ break;
+ } else {
+ throw new IllegalArgumentException(printRed("Error: Number of students to add must be greater than 0 and less or equal to " + maxStudents));
+ }
+ } catch (InputMismatchException e) {
+ scanner.nextLine();
+ System.err.println(printRed("Oops! You need to enter a valid number."));
+ } catch (IllegalArgumentException e) {
+ scanner.nextLine();
+ System.err.println(e.getMessage());
+ }
+ }
+
+ List studentList = new ArrayList<>();
+ for (int i = 0; i < numberStudents; i++) {
+ System.out.println(printBlue("Enter the id of the student:"));
+ studentId = scanner.nextLine();
+ studentList.add(studentId);
+ }
+
+ System.out.println("These are all the courses available:");
+ showAllCourses(school.getCourseMap());
+ System.out.println("");
+ System.out.println(printBlue("Enter the id of the course:"));
+ courseId = scanner.nextLine();
+ System.out.println(printBlueBold("Please wait, enrolling students..."));
+ System.out.println("");
+ System.out.println("");
+ try{
+ enrollStudents(studentList, courseId, school);
+
+ System.out.println(printYellow("Congratulations! Your students have been successfully enrolled to "
+ + CommandUtils.getCourseById(school.getCourseMap(), courseId).getName() + "."));
+
+ System.out.println("");
+ }catch(IllegalArgumentException e){
+ System.out.println("Error: "+e.getMessage());
+ }
+ break;
+ case 16:
+ System.out.println(printYellow("Closing program."));
+ scanner.close();
+ break;
+ }
+ }while(choiceMenu != 16);
+
+ }
+
+}
diff --git a/src/main/java/org/ConsoleColors.java b/src/main/java/org/ConsoleColors.java
new file mode 100644
index 0000000..3d17b27
--- /dev/null
+++ b/src/main/java/org/ConsoleColors.java
@@ -0,0 +1,76 @@
+package org;
+
+public class ConsoleColors {
+ // Reset
+ public static final String RESET = "\033[0m"; // Text Reset
+
+ // Regular Colors
+ public static final String BLACK = "\033[0;30m"; // BLACK
+ public static final String RED = "\033[0;31m"; // RED
+ public static final String GREEN = "\033[0;32m"; // GREEN
+ public static final String YELLOW = "\033[0;33m"; // YELLOW
+ public static final String BLUE = "\033[0;34m"; // BLUE
+ public static final String PURPLE = "\033[0;35m"; // PURPLE
+ public static final String CYAN = "\033[0;36m"; // CYAN
+ public static final String WHITE = "\033[0;37m"; // WHITE
+
+ // Bold
+ public static final String BLACK_BOLD = "\033[1;30m"; // BLACK
+ public static final String RED_BOLD = "\033[1;31m"; // RED
+ public static final String GREEN_BOLD = "\033[1;32m"; // GREEN
+ public static final String YELLOW_BOLD = "\033[1;33m"; // YELLOW
+ public static final String BLUE_BOLD = "\033[1;34m"; // BLUE
+ public static final String PURPLE_BOLD = "\033[1;35m"; // PURPLE
+ public static final String CYAN_BOLD = "\033[1;36m"; // CYAN
+ public static final String WHITE_BOLD = "\033[1;37m"; // WHITE
+
+ // Underline
+ public static final String BLACK_UNDERLINED = "\033[4;30m"; // BLACK
+ public static final String RED_UNDERLINED = "\033[4;31m"; // RED
+ public static final String GREEN_UNDERLINED = "\033[4;32m"; // GREEN
+ public static final String YELLOW_UNDERLINED = "\033[4;33m"; // YELLOW
+ public static final String BLUE_UNDERLINED = "\033[4;34m"; // BLUE
+ public static final String PURPLE_UNDERLINED = "\033[4;35m"; // PURPLE
+ public static final String CYAN_UNDERLINED = "\033[4;36m"; // CYAN
+ public static final String WHITE_UNDERLINED = "\033[4;37m"; // WHITE
+
+ // Background
+ public static final String BLACK_BACKGROUND = "\033[40m"; // BLACK
+ public static final String RED_BACKGROUND = "\033[41m"; // RED
+ public static final String GREEN_BACKGROUND = "\033[42m"; // GREEN
+ public static final String YELLOW_BACKGROUND = "\033[43m"; // YELLOW
+ public static final String BLUE_BACKGROUND = "\033[44m"; // BLUE
+ public static final String PURPLE_BACKGROUND = "\033[45m"; // PURPLE
+ public static final String CYAN_BACKGROUND = "\033[46m"; // CYAN
+ public static final String WHITE_BACKGROUND = "\033[47m"; // WHITE
+
+ // High Intensity
+ public static final String BLACK_BRIGHT = "\033[0;90m"; // BLACK
+ public static final String RED_BRIGHT = "\033[0;91m"; // RED
+ public static final String GREEN_BRIGHT = "\033[0;92m"; // GREEN
+ public static final String YELLOW_BRIGHT = "\033[0;93m"; // YELLOW
+ public static final String BLUE_BRIGHT = "\033[0;94m"; // BLUE
+ public static final String PURPLE_BRIGHT = "\033[0;95m"; // PURPLE
+ public static final String CYAN_BRIGHT = "\033[0;96m"; // CYAN
+ public static final String WHITE_BRIGHT = "\033[0;97m"; // WHITE
+
+ // Bold High Intensity
+ public static final String BLACK_BOLD_BRIGHT = "\033[1;90m"; // BLACK
+ public static final String RED_BOLD_BRIGHT = "\033[1;91m"; // RED
+ public static final String GREEN_BOLD_BRIGHT = "\033[1;92m"; // GREEN
+ public static final String YELLOW_BOLD_BRIGHT = "\033[1;93m";// YELLOW
+ public static final String BLUE_BOLD_BRIGHT = "\033[1;94m"; // BLUE
+ public static final String PURPLE_BOLD_BRIGHT = "\033[1;95m";// PURPLE
+ public static final String CYAN_BOLD_BRIGHT = "\033[1;96m"; // CYAN
+ public static final String WHITE_BOLD_BRIGHT = "\033[1;97m"; // WHITE
+
+ // High Intensity backgrounds
+ public static final String BLACK_BACKGROUND_BRIGHT = "\033[0;100m";// BLACK
+ public static final String RED_BACKGROUND_BRIGHT = "\033[0;101m";// RED
+ public static final String GREEN_BACKGROUND_BRIGHT = "\033[0;102m";// GREEN
+ public static final String YELLOW_BACKGROUND_BRIGHT = "\033[0;103m";// YELLOW
+ public static final String BLUE_BACKGROUND_BRIGHT = "\033[0;104m";// BLUE
+ public static final String PURPLE_BACKGROUND_BRIGHT = "\033[0;105m"; // PURPLE
+ public static final String CYAN_BACKGROUND_BRIGHT = "\033[0;106m"; // CYAN
+ public static final String WHITE_BACKGROUND_BRIGHT = "\033[0;107m"; // WHITE
+}
diff --git a/src/main/java/org/Course.java b/src/main/java/org/Course.java
new file mode 100644
index 0000000..e94c0a2
--- /dev/null
+++ b/src/main/java/org/Course.java
@@ -0,0 +1,105 @@
+package org;
+
+import org.Teacher;
+
+import java.util.List;
+import java.util.Objects;
+
+public class Course {
+ private String courseId;
+ private String name;
+ private double price;
+ private double money_earned;
+ private Teacher teacher = null;
+ private static int idCounter = 1;
+
+ public Course(String name, double price, double money_earned) {
+ assignCourseId();
+ setName(name);
+ try {
+ setPrice(price);
+ } catch(IllegalArgumentException e){
+ System.out.println("Error: "+e.getMessage());
+ }
+ setMoney_earned(0.0);
+ setTeacher(null);
+ }
+
+ public String getCourseId() {
+ return courseId;
+ }
+
+ private void assignCourseId() {
+ this.courseId = "C" + String.valueOf(idCounter++);
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(double price) {
+ if (price < 0) {
+ throw new IllegalArgumentException("Salary can not be negative value");
+ } else {
+ this.price = price;
+ }
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+
+ public double getMoney_earned() {
+ return money_earned;
+ }
+ public void updateMoney_earned(double money_earned) {
+ this.money_earned = money_earned;
+ }
+
+ public void setMoney_earned(double money_earned) {
+ this.money_earned = money_earned;
+ }
+
+ public void setTeacher(Teacher teacher){
+ this.teacher = teacher;
+ }
+
+ public Teacher getTeacher(){
+ return this.teacher;
+ }
+
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Course course)) return false;
+ return Double.compare(getPrice(), course.getPrice()) == 0 && Double.compare(getMoney_earned(), course.getMoney_earned()) == 0 && Objects.equals(getName(), course.getName()) && Objects.equals(getTeacher(), course.getTeacher());
+ }
+ public void removeTeacher(){
+ this.teacher = null;
+ }
+
+
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getName(), getPrice(), getMoney_earned(), getTeacher());
+ }
+
+ public String getInfo() {
+ String name = getName().length() > 16 ? getName().substring(0, 15) + " ." : getName();
+ String teacherName = "";
+ if(teacher != null){
+ teacherName = getTeacher().getName().length() > 16 ? getTeacher().getName().substring(0, 15) + " ." : getTeacher().getName();
+ }
+ return String.format(" %-4s│ %-17s │ %-13s│ %-17s ",
+ courseId, name, getPrice(), teacherName);
+ }
+}
+
diff --git a/src/main/java/org/Main.java b/src/main/java/org/Main.java
new file mode 100644
index 0000000..5c386cc
--- /dev/null
+++ b/src/main/java/org/Main.java
@@ -0,0 +1,10 @@
+package org;
+
+public class Main {
+ public static void main(String[] args) {
+
+ School school = SchoolCreator.schoolCreatorNew();
+ Commands.menuCommands(school);
+
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/PrintUtils.java b/src/main/java/org/PrintUtils.java
new file mode 100644
index 0000000..78e09ec
--- /dev/null
+++ b/src/main/java/org/PrintUtils.java
@@ -0,0 +1,25 @@
+package org;
+
+public class PrintUtils {
+
+ static String printBlue(String text) {
+ return ConsoleColors.BLUE + text + ConsoleColors.RESET;
+ }
+
+ static String printPurple(String text) {
+ return ConsoleColors.PURPLE + text + ConsoleColors.RESET;
+ }
+
+ static String printYellow(String text) {
+ return ConsoleColors.YELLOW + text + ConsoleColors.RESET;
+ }
+
+ static String printRed(String text) {
+ return ConsoleColors.RED + text + ConsoleColors.RESET;
+ }
+
+ static String printCyan(String text) { return ConsoleColors.CYAN + text + ConsoleColors.RESET; }
+
+ static String printBlueBold(String text) { return ConsoleColors.BLUE_BOLD + text + ConsoleColors.RESET; }
+
+}
diff --git a/src/main/java/org/School.java b/src/main/java/org/School.java
new file mode 100644
index 0000000..c2ab97b
--- /dev/null
+++ b/src/main/java/org/School.java
@@ -0,0 +1,57 @@
+package org;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+public class School {
+ private String name;
+ LinkedHashMap courseMap;
+ LinkedHashMap teacherMap;
+ LinkedHashMap studentMap;
+
+
+ public School(String name, List listTeacher, List listCourse, List listStudent) {
+ setName(name);
+ setHashmapTeacher(listTeacher);
+ setHashmapCourse(listCourse);
+ setHashmapStudent(listStudent);
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setHashmapTeacher(List listTeacher) {
+ teacherMap = new LinkedHashMap<>();
+ for (Teacher teacher : listTeacher){
+ teacherMap.put(teacher.getTeacherId(), teacher);
+ }
+ }
+ public void setHashmapCourse(List listCourse) {
+ courseMap = new LinkedHashMap<>();
+ for (Course course : listCourse){
+ courseMap.put(course.getCourseId(), course);
+ }
+ }
+ public void setHashmapStudent(List listStudent) {
+ studentMap = new LinkedHashMap<>();
+ for (Student student : listStudent){
+ studentMap.put(student.getStudentId(), student);
+ }
+ }
+
+ public String getName() {
+ return this.name;
+ }
+ public LinkedHashMap getCourseMap() {
+ return this.courseMap;
+ }
+ public LinkedHashMap getTeacherMap() {
+ return this.teacherMap;
+ }
+
+ public LinkedHashMap getStudentMap() {
+ return this.studentMap;
+ }
+}
diff --git a/src/main/java/org/SchoolCreator.java b/src/main/java/org/SchoolCreator.java
new file mode 100644
index 0000000..b42bcfd
--- /dev/null
+++ b/src/main/java/org/SchoolCreator.java
@@ -0,0 +1,175 @@
+package org;
+
+import java.util.*;
+import static org.PrintUtils.*;
+
+public class SchoolCreator {
+
+ private static String schoolName = "";
+ private static List teachers = new ArrayList<>();
+ private static List courses = new ArrayList<>();
+ private static List students = new ArrayList<>();
+
+ public static School schoolCreatorNew(){
+ initialMenu();
+ itemCreator("teacher", schoolName, teachers, null);
+ itemCreator("course", schoolName, courses, teachers);
+ itemCreator("student", schoolName, students, null);
+ return new School(schoolName, teachers, courses, students);
+ }
+
+ public static void initialMenu(){
+ Scanner scanner = new Scanner(System.in);
+
+ System.out.println("Hi! \n");
+ System.out.println(("Welcome to the School Manager Tool. \n"));
+
+ System.out.println(printBlue("Please, text the name for your school:"));
+ schoolName = scanner.nextLine();
+
+ while (schoolName == "") {
+ System.out.println(printRed("School can't be blank"));
+ schoolName = scanner.nextLine();
+
+ }
+ System.out.println("");
+ System.out.println(printYellow("Perfect, we have created the school: ") + printPurple(schoolName));
+ System.out.println("");
+ }
+
+ public static void itemCreator(String type, String schoolName, List collection, List teachers) {
+ boolean is_num = false;
+ int totalItems = 0;
+ Scanner scanner = new Scanner(System.in);
+
+ while (!is_num) {
+ System.out.println(printBlue("How many " + type + "s are in " + schoolName + "?"));
+ try {
+ totalItems = scanner.nextInt();
+ scanner.nextLine();
+ if (totalItems > 0) {
+ System.out.println("Okey, let's create now each " + type + ".");
+
+ for (int i = 0; i < totalItems; i++) {
+ System.out.println("");
+ System.out.println(type.toUpperCase() + " " + (i+1) + ":");
+ if (Objects.equals(type, "teacher")) {
+ teacherCreator(collection);
+ } else if(Objects.equals(type, "course")) {
+ courseCreator(collection, teachers);
+ } else if(Objects.equals(type, "student")) {
+ studentCreator(collection);
+ } else {
+ System.err.println("Type not valid.");
+ }
+ }
+ System.out.println("");
+ System.out.println(printYellow("Congratulations! We have created all the " + type + "s."));
+ System.out.println("");
+ is_num = true;
+ } else {
+ System.err.println("Oops! You need to have at least one " + type + ".");
+ }
+ } catch (InputMismatchException ie) {
+ scanner.nextLine();
+ System.err.println("Oops! You need to enter a number.");
+ }
+ }
+ is_num = false;
+ }
+
+ private static void teacherCreator(List teachers){
+ boolean is_num = false;
+ String name = "";
+ double salary = 00.00;
+ Scanner scanner = new Scanner(System.in);
+
+ System.out.println(printBlue("Enter teacher name:"));
+ name = scanner.nextLine();
+ System.out.println(printBlue("Enter teacher salary:"));
+ while (!is_num) {
+ try {
+ salary = scanner.nextDouble();
+ scanner.nextLine();
+ is_num = true;
+ } catch (InputMismatchException ie) {
+ scanner.nextLine();
+ System.err.println("Oops! You need to enter a number.");
+ }
+ }
+
+ Teacher teacher = new Teacher(name, salary);
+ teacher.getInfo();
+ teachers.add(teacher);
+ }
+
+ private static void courseCreator(List courses, List teachers){
+ boolean is_num = false;
+ String name = "";
+ double price = 00.00;
+ int teacherSelection = 0;
+ Scanner scanner = new Scanner(System.in);
+
+ System.out.println(printBlue("Enter course name:"));
+ name = scanner.nextLine();
+ System.out.println(printBlue("Enter course price:"));
+ while (!is_num) {
+ try {
+ price = scanner.nextDouble();
+ scanner.nextLine();
+ is_num = true;
+ } catch (InputMismatchException ie) {
+ scanner.nextLine();
+ System.err.println("Oops! You need to enter a number.");
+ }
+ }
+ is_num = false;
+ /*
+ System.out.println(printBlue("Select an associated teacher:"));
+ System.out.println("0 - No teacher associated");
+ for (int i = 0; i < teachers.size(); i++) {
+ System.out.println((i+1) + " - " + teachers.get(i).getName() + " (" + teachers.get(i).getSalary() + "€)");
+ }
+
+ while (!is_num) {
+ try {
+ teacherSelection = scanner.nextInt();
+ scanner.nextLine();
+ is_num = true;
+ } catch (InputMismatchException ie) {
+ scanner.nextLine();
+ System.err.println("Oops! You need to enter a number.");
+ }
+ }
+
+ Course course = null;
+ if (teacherSelection == 0) {
+ // course = new Course(name, price, (double) 0);
+ } else {
+ course = new Course(name, price, (double) 0);
+ }
+ */
+ // TODO added por victoria porque petaba
+ Course course = new Course(name, price, (double) 0);
+ //course.getInfo();
+ courses.add(course);
+ }
+
+ private static void studentCreator(List students){
+ String name = "";
+ String address = "";
+ String email = "";
+ Scanner scanner = new Scanner(System.in);
+
+ System.out.println(printBlue("Enter student name:"));
+ name = scanner.nextLine();
+ System.out.println(printBlue("Enter student address:"));
+ address = scanner.nextLine();
+ System.out.println(printBlue("Enter student email:"));
+ email = scanner.nextLine();
+
+ Student student = new Student(name, address, email);
+ student.getInfo();
+ students.add(student);
+ }
+}
diff --git a/src/main/java/org/Student.java b/src/main/java/org/Student.java
new file mode 100644
index 0000000..70d9cdb
--- /dev/null
+++ b/src/main/java/org/Student.java
@@ -0,0 +1,113 @@
+package org;
+
+
+import java.util.Objects;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import java.util.UUID;
+
+public class Student {
+ private String studentId;
+ private String name;
+ private String address;
+ private String email;
+ private Course course;
+
+ private static int idCounter = 1;
+
+ // Constructor
+ public Student(String name, String address, String email) {
+ assignCourseId();
+ setName(name);
+ setAddress(address);
+ setEmail(email);
+
+
+ }
+
+ private void assignCourseId(){
+ this.studentId = "S" + String.valueOf(idCounter++);
+ }
+
+ // Getters
+ public String getStudentId() {
+ return studentId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public Course getCourse() {return course;}
+ public void removeCourse(){this.course = null;}
+
+
+
+ // Setters
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public void setCourse(Course course) {
+ this.course = course;
+ }
+
+
+
+
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Student student)) return false;
+ return Objects.equals(getName(), student.getName()) && Objects.equals(getAddress(), student.getAddress()) && Objects.equals(getEmail(), student.getEmail()) && Objects.equals(getCourse(), student.getCourse());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getName(), getAddress(), getEmail(), getCourse());
+ }
+
+
+ public String getInfo() {
+ String name = getName().length() > 17 ? getName().substring(0, 16) + " ." : getName();
+ String address = getAddress().length() > 17 ? getAddress().substring(0, 16) + " ." : getAddress();
+ String email = getEmail().length() > 17 ? getEmail().substring(0, 16) + " ." : getEmail();
+ String courseName = "";
+ if(course != null){
+ courseName = getCourse().getName().length() > 17 ? getCourse().getName().substring(0, 16) + " ." : getCourse().getName();
+ }
+ return String.format(" %-4s│ %-18s │ %-18s │ %-18s │ %-18s ",
+ studentId, name, address, email, courseName);
+
+// if(enrolledCourses.isEmpty()){
+// return "Student - ID: " + this.studentId + " | Name: " + getName() +
+// " | Address: " + getAddress() + " | Email: " + getEmail();
+// } else {
+// return "Student - ID: " + this.studentId + " | Name: " + getName() +
+// " | Address: " + getAddress() + " | Email: " + getEmail()
+// + " | Enrolled in: " + getInfoCourses();
+// }
+
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/Teacher.java b/src/main/java/org/Teacher.java
new file mode 100644
index 0000000..a350111
--- /dev/null
+++ b/src/main/java/org/Teacher.java
@@ -0,0 +1,83 @@
+package org;
+
+import java.util.List;
+import java.util.Objects;
+
+public class Teacher {
+ private String studentId;
+ private String name;
+ private double salary;
+ private List courses;
+ private static int idCounter = 1;
+
+ public Teacher(String name, double salary) {
+ assignTeacherId();
+ setName(name);
+ try {
+ setSalary(salary);
+ } catch(IllegalArgumentException e){
+ System.out.println("Error: "+e.getMessage());
+ }
+ }
+
+ public boolean getTeacherById(String idToCheck){
+ return this.studentId.equals(idToCheck);
+ }
+ private void assignTeacherId(){
+ this.studentId = "T" + String.valueOf(idCounter++);
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setSalary(double salary) {
+ if (salary < 0){
+ throw new IllegalArgumentException("Salary can not be negative value");
+ } else {
+ this.salary = salary;
+ }
+ }
+
+ public void setCourses(List courses) {
+ this.courses = courses;
+ }
+
+ public String getTeacherId() {
+ return this.studentId;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public double getSalary() {
+ return this.salary;
+ }
+
+ public List getCourses() {
+ return this.courses;
+ }
+
+ public void addCourseToTeacher(Course course){
+ this.courses.add(course);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Teacher teacher)) return false;
+ return Double.compare(getSalary(), teacher.getSalary()) == 0 && Objects.equals(getName(), teacher.getName()) && Objects.equals(getCourses(), teacher.getCourses());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getName(), getSalary(), getCourses());
+ }
+
+ public String getInfo() {
+ String name = getName().length() > 16 ? getName().substring(0, 15) + " ." : getName();
+ return String.format(" %-4s│ %-17s │ %-13s",
+ getTeacherId(), name, getSalary());
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/org/CommandTest.java b/src/test/java/org/CommandTest.java
new file mode 100644
index 0000000..8873d4b
--- /dev/null
+++ b/src/test/java/org/CommandTest.java
@@ -0,0 +1,127 @@
+package org;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.Command.assignTeacher;
+import static org.junit.jupiter.api.Assertions.*;
+import java.util.ArrayList; // Import ArrayList class from java.util package
+import java.util.List;
+
+class CommandTest {
+
+ Command command;
+ School school;
+
+ @BeforeEach
+ void setUp(){
+ command = new Command();
+ school = new School("test2", new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
+
+ }
+
+ @Test
+ void testEnrollStudent() {
+ Student student = new Student("John Doe", "123 Main St", "john.doe@example.com");
+ school.getStudentMap().put(student.getStudentId(), student);
+
+ Course course = new Course("C2", 100.0, 0.0);
+ school.getCourseMap().put(course.getCourseId(), course);
+
+ student.setCourse(course);
+
+ assertEquals(course, student.getCourse());
+ }
+
+ @Test
+ void testShowProfit() {
+ Course course1 = new Course("C1", 100.0, 0.0);
+ school.getCourseMap().put(course1.getCourseId(), course1);
+
+ Course course2 = new Course("C2", 150.0, 0.0);
+ school.getCourseMap().put(course2.getCourseId(), course2);
+
+ double totalMoneyEarned = course1.getPrice() + course2.getPrice();
+ double totalTeacherSalaries = 0; // Assume no teacher salaries in this case
+
+ double profit = totalMoneyEarned - totalTeacherSalaries;
+
+ try {
+ double calculatedProfit = totalMoneyEarned - totalTeacherSalaries;
+ assertEquals(profit, calculatedProfit);
+ } catch (IllegalArgumentException e) {
+ fail("Error calculating profit: " + e.getMessage());
+ }
+ }
+
+ @Test
+ void testAssignTeacher(){
+ //School school = new School("test2", new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
+ Teacher teacher = new Teacher("Juan", 2000);
+ //asignar el teacher a school
+ school.getTeacherMap().put(teacher.getTeacherId(), teacher);
+ Course course = new Course("Ciencia", 500, 0);
+ //asignar el course a school
+ school.getCourseMap().put(course.getCourseId(), course);
+ assertEquals("Ciencia", course.getName());
+ Command.assignTeacher(teacher.getTeacherId(), course.getCourseId(), school);
+ assertEquals("Juan", course.getTeacher().getName());
+ }
+
+ @Test
+ void testRemoveTeacherFromCourse(){
+ Teacher teacher = new Teacher("Juan", 2000);
+ //asignar el teacher a school
+ school.getTeacherMap().put(teacher.getTeacherId(), teacher);
+ Course course = new Course("Mates", 100, 0);
+ //asignar el course a school
+ school.getCourseMap().put(course.getCourseId(), course);
+ Command.assignTeacher(teacher.getTeacherId(), course.getCourseId(), school);
+ Command.removeTeacherFromCourse(course.getCourseId(), school);
+ assertNull(course.getTeacher());
+ }
+
+ @Test
+ void testUnenrollStudent(){
+ Student student = new Student("Pepe", "dirección", "email");
+ school.getStudentMap().put(student.getStudentId(), student);
+ Course course = new Course("Mates", 100, 0);
+ //asignar el course a school
+ school.getCourseMap().put(course.getCourseId(), course);
+ Command.enrollStudent(student.getStudentId(), course.getCourseId(), school);
+ assertEquals( course, student.getCourse());
+ }
+
+ @Test
+ void testIsStudentEnrolledInCourse(){
+ Student student = new Student("Pepe", "dirección", "email");
+ school.getStudentMap().put(student.getStudentId(), student);
+ Course course = new Course("Mates", 100, 0);
+ school.getCourseMap().put(course.getCourseId(), course);
+ assertFalse(Command.isStudentEnrolledInCourse(student, course.getCourseId()));
+ Command.enrollStudent(student.getStudentId(), course.getCourseId(), school);
+ assertTrue(Command.isStudentEnrolledInCourse(student, course.getCourseId()));
+ }
+
+ @Test
+ void testEnrollStudents(){
+ List studentList = new ArrayList<>();
+ Student student1 = new Student("Pepe", "dirección", "email");
+ Student student2 = new Student("María", "calle", "gmail");
+ school.getStudentMap().put(student1.getStudentId(), student1);
+ school.getStudentMap().put(student2.getStudentId(), student2);
+ studentList.add(student1.getStudentId());
+ studentList.add(student2.getStudentId());
+
+ Course course = new Course("Mates", 100, 0);
+ school.getCourseMap().put(course.getCourseId(), course);
+
+ Command.enrollStudents(studentList, course.getCourseId(), school);
+ assertEquals(course, student1.getCourse());
+ assertEquals(course, student2.getCourse());
+ assertTrue(Command.isStudentEnrolledInCourse(student1, course.getCourseId()));
+ assertTrue(Command.isStudentEnrolledInCourse(student2, course.getCourseId()));
+
+
+ }
+}
diff --git a/src/test/java/org/CommandUtilsTest.java b/src/test/java/org/CommandUtilsTest.java
new file mode 100644
index 0000000..c2e9dbc
--- /dev/null
+++ b/src/test/java/org/CommandUtilsTest.java
@@ -0,0 +1,85 @@
+package org;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import static org.CommandUtils.*;
+
+import static org.CommandUtils.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class CommandUtilsTest {
+
+
+ private static List listTeacher;
+ private static List listCourse;
+ private static List listStudent;
+
+ private static School school;
+
+ @BeforeAll
+ static void setUp(){
+ listTeacher = new ArrayList<>();
+ listTeacher.add(new Teacher("Victoria", 1000));
+ listTeacher.add(new Teacher("Katia", 1500));
+ listTeacher.add(new Teacher("Arturo", 1200));
+ listCourse = new ArrayList<>();
+ listCourse.add(new Course("math", 340, 34));
+ listCourse.add(new Course("history", 500, 34));
+ listStudent = new ArrayList<>();
+ listStudent.add(new Student("Anna", "street 1", "anna@gmail.com"));
+ listStudent.add(new Student("Julia", "street 2", "julia@gmail.com"));
+
+ school = new School("school", listTeacher, listCourse, listStudent);
+ }
+
+ @Test
+ @DisplayName("Check getStudentById method")
+ void getStudentByIdTest(){
+ Student student = new Student("Anna", "street 1", "anna@gmail.com");
+ assertEquals(student, getStudentById(school.getStudentMap(), "S1"));
+ }
+
+ @Test
+ @DisplayName("Check getTeacherById method")
+ void getTeacherByIdTest(){
+ Teacher teacher = new Teacher("Katia", 1500);
+ assertEquals(teacher, getTeacherById(school.getTeacherMap(), "T2"));
+ }
+
+ @Test
+ @DisplayName("Check getCourseById method")
+ void getCourseByIdTest(){
+ Course course = new Course("math", 340, 34);
+ assertEquals(course, getCourseById(school.getCourseMap(), "C1"));
+ }
+
+ @Test
+ @DisplayName("Check looUpStudent command with invalid ID")
+ void looUpStudentTest(){
+ assertThrows(IllegalArgumentException.class, () -> {
+ lookUpStudent(school.getStudentMap(), "invalidID");
+ });
+ }
+
+ @Test
+ @DisplayName("Check looUpTeacher command with invalid ID")
+ void looUpTeacherTest(){
+ assertThrows(IllegalArgumentException.class, () -> {
+ lookUpTeacher(school.getTeacherMap(), "invalidID");
+ });
+ }
+
+ @Test
+ @DisplayName("Check looUpCourse command with invalid ID")
+ void looUpCourseTest(){
+ assertThrows(IllegalArgumentException.class, () -> {
+ lookUpCourse(school.getCourseMap(), "invalidID");
+ });
+ }
+}
diff --git a/src/test/java/org/MainTest.java b/src/test/java/org/MainTest.java
new file mode 100644
index 0000000..997aa3a
--- /dev/null
+++ b/src/test/java/org/MainTest.java
@@ -0,0 +1,4 @@
+package org;
+
+public class MainTest {
+}
diff --git a/src/test/java/org/StudentTest.java b/src/test/java/org/StudentTest.java
new file mode 100644
index 0000000..9432531
--- /dev/null
+++ b/src/test/java/org/StudentTest.java
@@ -0,0 +1,17 @@
+package org;
+
+public class StudentTest {
+ public static void main(String[] args) {
+ Student student = new Student("", "", "");
+
+ student.setName("John Doe");
+ student.setAddress("Calle Falsa 123, Springfield");
+ student.setEmail("johndoe@test.com");
+
+ System.out.println("Student ID: " + student.getStudentId());
+ System.out.println("Name: " + student.getName());
+ System.out.println("Address: " + student.getAddress());
+ System.out.println("Email: " + student.getEmail());
+ System.out.println("Course: " + student.getCourse());
+ }
+}