diff --git a/.gitignore b/.gitignore
index 8594069a..f86a1636 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,4 +23,8 @@
hs_err_pid*
replay_pid*
-.vscode
\ No newline at end of file
+.vscode
+.DS_Store
+data.txt
+testdata.txt
+.idea
\ No newline at end of file
diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java
index 272c94c9..4c34a846 100644
--- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java
+++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Course.java
@@ -1,9 +1,28 @@
package dev.coms4156.project.individualproject;
-import java.io.*;
-
+import java.io.Serial;
+import java.io.Serializable;
+
+/**
+ *
This Course class represents a course in a department.
+ *
+ * It includes the instructor name, course location, time slot,
+ * and the capacity for student enrollment.
+ *
+ * The class allows students to enroll and drop the course, and it can determine
+ * if the course is full or not. It also allows reassignment of the instructor,
+ * location, and time slot.
+ */
public class Course implements Serializable {
+ @Serial
+ private static final long serialVersionUID = 123456L;
+ private final int enrollmentCapacity;
+ private int enrolledStudentCount;
+ private String courseLocation;
+ private String instructorName;
+ private String courseTimeSlot;
+
/**
* Constructs a new Course object with the given parameters. Initial count starts at 0.
*
@@ -17,79 +36,116 @@ public Course(String instructorName, String courseLocation, String timeSlot, int
this.instructorName = instructorName;
this.courseTimeSlot = timeSlot;
this.enrollmentCapacity = capacity;
- this.enrolledStudentCount = 500;
+ this.enrolledStudentCount = 0;
}
- /**
+ /**
* Enrolls a student in the course if there is space available.
*
* @return true if the student is successfully enrolled, false otherwise.
*/
public boolean enrollStudent() {
- enrolledStudentCount++;
- return false;
+ if (enrolledStudentCount >= enrollmentCapacity) {
+ return false;
+ }
+ enrolledStudentCount++;
+ return true;
}
- /**
+ /**
* Drops a student from the course if a student is enrolled.
*
* @return true if the student is successfully dropped, false otherwise.
*/
public boolean dropStudent() {
+ if (enrolledStudentCount <= 0) {
+ return false;
+ }
enrolledStudentCount--;
- return false;
+ return true;
}
-
+ /**
+ * Gets the location of the course.
+ *
+ * @return the location of the course.
+ */
public String getCourseLocation() {
- return this.instructorName;
+ return this.courseLocation;
}
-
+ /**
+ * Gets the name of the instructor of the course.
+ *
+ * @return the name of the instructor of the course.
+ */
public String getInstructorName() {
- return this.courseLocation;
+ return this.instructorName;
}
-
+ /**
+ * Gets the time slot during when the course is hold.
+ *
+ * @return the time slot during when the course is hold.
+ */
public String getCourseTimeSlot() {
return this.courseTimeSlot;
}
-
+ /**
+ * Gets the string containing the course information.
+ *
+ * @return the string containing the course information.
+ */
public String toString() {
- return "\nInstructor: " + instructorName + "; Location: " + courseLocation + "; Time: " + courseTimeSlot;
+ return "\nInstructor: " + instructorName
+ + "; Location: " + courseLocation
+ + "; Time: " + courseTimeSlot;
}
-
+ /**
+ * Changes the name of instructor of the course to another instructor's.
+ *
+ * @param newInstructorName A {@code String} containing the name of
+ * the new instructor.
+ */
public void reassignInstructor(String newInstructorName) {
this.instructorName = newInstructorName;
}
-
+ /**
+ * Changes the location of the Course to another location.
+ *
+ * @param newLocation A {@code String} containing the new location.
+ */
public void reassignLocation(String newLocation) {
this.courseLocation = newLocation;
}
-
+ /**
+ * Changes the time slot of the course to another time slot.
+ *
+ * @param newTime A {@code String} containing the new time slot.
+ */
public void reassignTime(String newTime) {
this.courseTimeSlot = newTime;
}
-
+ /**
+ * Sets the current number of enrolled student.
+ *
+ * @param count A {@code int} indicating the current enrolled student number.
+ */
public void setEnrolledStudentCount(int count) {
this.enrolledStudentCount = count;
}
-
+ /**
+ * Checks if the course is full.
+ *
+ * @return A {@code boolean}. true if the course is full, otherwise false.
+ */
public boolean isCourseFull() {
- return enrollmentCapacity > enrolledStudentCount;
+ return enrollmentCapacity <= enrolledStudentCount;
}
-
- @Serial
- private static final long serialVersionUID = 123456L;
- private final int enrollmentCapacity;
- private int enrolledStudentCount;
- private String courseLocation;
- private String instructorName;
- private String courseTimeSlot;
}
diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java
index 4bab0f08..99a0e5d2 100644
--- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java
+++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/Department.java
@@ -1,7 +1,9 @@
package dev.coms4156.project.individualproject;
-import java.io.*;
-import java.util.*;
+import java.io.Serial;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
/**
@@ -11,6 +13,13 @@
*/
public class Department implements Serializable {
+ @Serial
+ private static final long serialVersionUID = 234567L;
+ private final HashMap courses;
+ private final String departmentChair;
+ private final String deptCode;
+ private int numberOfMajors;
+
/**
* Constructs a new Department object with the given parameters.
*
@@ -33,7 +42,7 @@ public Department(String deptCode, HashMap courses, String depar
* @return The number of majors.
*/
public int getNumberOfMajors() {
- return -this.numberOfMajors;
+ return this.numberOfMajors;
}
/**
@@ -42,7 +51,7 @@ public int getNumberOfMajors() {
* @return The name of the department chair.
*/
public String getDepartmentChair() {
- return "this.departmentChair";
+ return this.departmentChair;
}
/**
@@ -65,7 +74,11 @@ public void addPersonToMajor() {
* Decreases the number of majors in the department by one if it's greater than zero.
*/
public void dropPersonFromMajor() {
- numberOfMajors--;
+ if (numberOfMajors > 0) {
+ numberOfMajors--;
+ } else {
+ System.out.println("numOfMajor is less than 0.\n");
+ }
}
/**
@@ -106,13 +119,6 @@ public String toString() {
result.append(deptCode).append(" ").append(key).append(": ").append(value.toString())
.append("\n");
}
- return "result.toString()";
+ return result.toString();
}
-
- @Serial
- private static final long serialVersionUID = 234567L;
- private HashMap courses;
- private String departmentChair;
- private String deptCode;
- private int numberOfMajors;
}
diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java
index 80860423..88e134e4 100644
--- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java
+++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/IndividualProjectApplication.java
@@ -1,302 +1,303 @@
package dev.coms4156.project.individualproject;
import jakarta.annotation.PreDestroy;
-import java.util.*;
-import org.springframework.boot.*;
+import java.util.HashMap;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
- * Class contains all the startup logic for the application.
+ * Class contains all the startup logic for the application.
*
- * DO NOT MODIFY ANYTHING BELOW THIS POINT WITH REGARD TO FUNCTIONALITY
- * YOU MAY MAKE STYLE/REFACTOR MODIFICATIONS AS NEEDED
+ * DO NOT MODIFY ANYTHING BELOW THIS POINT WITH REGARD TO FUNCTIONALITY
+ * YOU MAY MAKE STYLE/REFACTOR MODIFICATIONS AS NEEDED
*/
@SpringBootApplication
public class IndividualProjectApplication implements CommandLineRunner {
- /**
- * The main launcher for the service all it does
- * is make a call to the overridden run method.
- *
- * @param args A {@code String[]} of any potential
- * runtime arguments
- */
- public static void main(String[] args) {
- SpringApplication.run(IndividualProjectApplication.class, args);
- }
+ //Database Instance
+ public static MyFileDatabase myFileDatabase;
+ private static boolean saveData = true;
- /**
- * This contains all the setup logic, it will mainly be focused
- * on loading up and creating an instance of the database based
- * off a saved file or will create a fresh database if the file
- * is not present.
- *
- * @param args A {@code String[]} of any potential runtime args
- */
- public void run(String[] args) {
- for (String arg : args) {
- if (arg.equals("setup")) {
- myFileDatabase = new MyFileDatabase(1, "./data.txt");
- resetDataFile();
- System.out.println("System Setup");
- return;
- }
- }
- myFileDatabase = new MyFileDatabase(0, "./data.txt");
- System.out.println("Start up");
- }
- /**
- * Overrides the database reference, used when testing.
- *
- * @param testData A {@code MyFileDatabase} object referencing test data.
- */
- public static void overrideDatabase(MyFileDatabase testData) {
- myFileDatabase = testData;
- saveData = false;
- }
+ /**
+ * The main launcher for the service all it does
+ * is make a call to the overridden run method.
+ *
+ * @param args A {@code String[]} of any potential
+ * runtime arguments
+ */
+ public static void main(String[] args) {
+ SpringApplication.run(IndividualProjectApplication.class, args);
+ }
- /**
- * Allows for data to be reset in event of errors.
- */
- public void resetDataFile() {
- String[] times = {"11:40-12:55", "4:10-5:25", "10:10-11:25", "2:40-3:55"};
- String[] locations = {"417 IAB", "309 HAV", "301 URIS"};
+ /**
+ * This contains all the setup logic, it will mainly be focused
+ * on loading up and creating an instance of the database based
+ * off a saved file or will create a fresh database if the file
+ * is not present.
+ *
+ * @param args A {@code String[]} of any potential runtime args
+ */
+ public void run(String[] args) {
+ for (String arg : args) {
+ if (arg.equals("setup")) {
+ myFileDatabase = new MyFileDatabase(1, "./data.txt");
+ resetDataFile();
+ System.out.println("System Setup");
+ return;
+ }
+ }
+ myFileDatabase = new MyFileDatabase(0, "./data.txt");
+ System.out.println("Start up");
+ }
- //data for coms dept
- Course coms1004 = new Course("Adam Cannon", locations[0], times[0], 400);
- coms1004.setEnrolledStudentCount(249);
- Course coms3134 = new Course("Brian Borowski", locations[2], times[1], 250);
- coms3134.setEnrolledStudentCount(242);
- Course coms3157 = new Course("Jae Lee", locations[0], times[1], 400);
- coms3157.setEnrolledStudentCount(311);
- Course coms3203 = new Course("Ansaf Salleb-Aouissi", locations[2], times[2], 250);
- coms3203.setEnrolledStudentCount(215);
- Course coms3261 = new Course("Josh Alman", locations[0], times[3], 150);
- coms3261.setEnrolledStudentCount(140);
- Course coms3251 = new Course("Tony Dear", "402 CHANDLER", "1:10-3:40", 125);
- coms3251.setEnrolledStudentCount(99);
- Course coms3827 = new Course("Daniel Rubenstein", "207 Math", times[2], 300);
- coms3827.setEnrolledStudentCount(283);
- Course coms4156 = new Course("Gail Kaiser", "501 NWC", times[2], 120);
- coms4156.setEnrolledStudentCount(109);
- HashMap courses = new HashMap<>();
- courses.put("1004", coms1004);
- courses.put("3134", coms3134);
- courses.put("3157", coms3157);
- courses.put("3203", coms3203);
- courses.put("3261", coms3261);
- courses.put("3251", coms3251);
- courses.put("3827", coms3827);
- courses.put("4156", coms4156);
- Department compSci = new Department("COMS", courses, "Luca Carloni", 2700);
- HashMap mapping = new HashMap<>();
- mapping.put("COMS", compSci);
+ /**
+ * Overrides the database reference, used when testing.
+ *
+ * @param testData A {@code MyFileDatabase} object referencing test data.
+ */
+ public static void overrideDatabase(MyFileDatabase testData) {
+ myFileDatabase = testData;
+ saveData = false;
+ }
- //data for econ dept
- Course econ1105 = new Course("Waseem Noor", locations[1], times[3], 210);
- econ1105.setEnrolledStudentCount(187);
- Course econ2257 = new Course("Tamrat Gashaw", "428 PUP", times[2], 125);
- econ2257.setEnrolledStudentCount(63);
- Course econ3211 = new Course("Murat Yilmaz", "310 FAY", times[1], 96);
- econ3211.setEnrolledStudentCount(81);
- Course econ3213 = new Course("Miles Leahey", "702 HAM", times[1], 86);
- econ3213.setEnrolledStudentCount(77);
- Course econ3412 = new Course("Thomas Piskula", "702 HAM", times[0], 86);
- econ3412.setEnrolledStudentCount(81);
- Course econ4415 = new Course("Evan D Sadler", locations[1], times[2], 110);
- econ4415.setEnrolledStudentCount(63);
- Course econ4710 = new Course("Matthieu Gomez", "517 HAM", "8:40-9:55", 86);
- econ4710.setEnrolledStudentCount(37);
- Course econ4840 = new Course("Mark Dean", "142 URIS", times[3], 108);
- econ4840.setEnrolledStudentCount(67);
+ /**
+ * Allows for data to be reset in event of errors.
+ */
+ public void resetDataFile() {
+ String[] times = {"11:40-12:55", "4:10-5:25", "10:10-11:25", "2:40-3:55"};
+ String[] locations = {"417 IAB", "309 HAV", "301 URIS"};
- courses = new HashMap<>();
- courses.put("1105", econ1105);
- courses.put("2257", econ2257);
- courses.put("3211", econ3211);
- courses.put("3213", econ3213);
- courses.put("3412", econ3412);
- courses.put("4415", econ4415);
- courses.put("4710", econ4710);
- courses.put("4840", econ4840);
+ //data for coms dept
+ Course coms1004 = new Course("Adam Cannon", locations[0], times[0], 400);
+ coms1004.setEnrolledStudentCount(249);
+ Course coms3134 = new Course("Brian Borowski", locations[2], times[1], 250);
+ coms3134.setEnrolledStudentCount(242);
+ Course coms3157 = new Course("Jae Lee", locations[0], times[1], 400);
+ coms3157.setEnrolledStudentCount(311);
+ Course coms3203 = new Course("Ansaf Salleb-Aouissi", locations[2], times[2], 250);
+ coms3203.setEnrolledStudentCount(215);
+ Course coms3261 = new Course("Josh Alman", locations[0], times[3], 150);
+ coms3261.setEnrolledStudentCount(140);
+ Course coms3251 = new Course("Tony Dear", "402 CHANDLER", "1:10-3:40", 125);
+ coms3251.setEnrolledStudentCount(99);
+ Course coms3827 = new Course("Daniel Rubenstein", "207 Math", times[2], 300);
+ coms3827.setEnrolledStudentCount(283);
+ Course coms4156 = new Course("Gail Kaiser", "501 NWC", times[2], 120);
+ coms4156.setEnrolledStudentCount(109);
+ HashMap courses = new HashMap<>();
+ courses.put("1004", coms1004);
+ courses.put("3134", coms3134);
+ courses.put("3157", coms3157);
+ courses.put("3203", coms3203);
+ courses.put("3261", coms3261);
+ courses.put("3251", coms3251);
+ courses.put("3827", coms3827);
+ courses.put("4156", coms4156);
+ Department compSci = new Department("COMS", courses, "Luca Carloni", 2700);
+ HashMap mapping = new HashMap<>();
+ mapping.put("COMS", compSci);
- Department econ = new Department("ECON", courses, "Michael Woodford", 2345);
- mapping.put("ECON", econ);
+ //data for econ dept
+ Course econ1105 = new Course("Waseem Noor", locations[1], times[3], 210);
+ econ1105.setEnrolledStudentCount(187);
+ Course econ2257 = new Course("Tamrat Gashaw", "428 PUP", times[2], 125);
+ econ2257.setEnrolledStudentCount(63);
+ Course econ3211 = new Course("Murat Yilmaz", "310 FAY", times[1], 96);
+ econ3211.setEnrolledStudentCount(81);
+ Course econ3213 = new Course("Miles Leahey", "702 HAM", times[1], 86);
+ econ3213.setEnrolledStudentCount(77);
+ Course econ3412 = new Course("Thomas Piskula", "702 HAM", times[0], 86);
+ econ3412.setEnrolledStudentCount(81);
+ Course econ4415 = new Course("Evan D Sadler", locations[1], times[2], 110);
+ econ4415.setEnrolledStudentCount(63);
+ Course econ4710 = new Course("Matthieu Gomez", "517 HAM", "8:40-9:55", 86);
+ econ4710.setEnrolledStudentCount(37);
+ Course econ4840 = new Course("Mark Dean", "142 URIS", times[3], 108);
+ econ4840.setEnrolledStudentCount(67);
- //data for ieor dept
- Course ieor2500 = new Course("Uday Menon", "627 MUDD", times[0], 50);
- ieor2500.setEnrolledStudentCount(52);
- Course ieor3404 = new Course("Christopher J Dolan", "303 MUDD", times[2], 73);
- ieor3404.setEnrolledStudentCount(80);
- Course ieor3658 = new Course("Daniel Lacker", "310 FAY", times[2], 96);
- ieor3658.setEnrolledStudentCount(87);
- Course ieor4102 = new Course("Antonius B Dieker", "209 HAM", times[2], 110);
- ieor4102.setEnrolledStudentCount(92);
- Course ieor4106 = new Course("Kaizheng Wang", "501 NWC", times[2], 150);
- ieor4106.setEnrolledStudentCount(161);
- Course ieor4405 = new Course("Yuri Faenza", "517 HAV", times[0], 80);
- ieor4405.setEnrolledStudentCount(19);
- Course ieor4511 = new Course("Michael Robbins", "633 MUDD", "9:00-11:30", 150);
- ieor4511.setEnrolledStudentCount(50);
- Course ieor4540 = new Course("Krzysztof M Choromanski", "633 MUDD", "7:10-9:40", 60);
- ieor4540.setEnrolledStudentCount(33);
+ courses = new HashMap<>();
+ courses.put("1105", econ1105);
+ courses.put("2257", econ2257);
+ courses.put("3211", econ3211);
+ courses.put("3213", econ3213);
+ courses.put("3412", econ3412);
+ courses.put("4415", econ4415);
+ courses.put("4710", econ4710);
+ courses.put("4840", econ4840);
- courses = new HashMap<>();
- courses.put("2500", ieor2500);
- courses.put("3404", ieor3404);
- courses.put("3658", ieor3658);
- courses.put("4102", ieor4102);
- courses.put("4106", ieor4106);
- courses.put("4405", ieor4405);
- courses.put("4511", ieor4511);
- courses.put("4540", ieor4540);
+ Department econ = new Department("ECON", courses, "Michael Woodford", 2345);
+ mapping.put("ECON", econ);
- Department ieor = new Department("IEOR", courses, "Jay Sethuraman", 67);
- mapping.put("IEOR", ieor);
+ //data for ieor dept
+ Course ieor2500 = new Course("Uday Menon", "627 MUDD", times[0], 50);
+ ieor2500.setEnrolledStudentCount(52);
+ Course ieor3404 = new Course("Christopher J Dolan", "303 MUDD", times[2], 73);
+ ieor3404.setEnrolledStudentCount(80);
+ Course ieor3658 = new Course("Daniel Lacker", "310 FAY", times[2], 96);
+ ieor3658.setEnrolledStudentCount(87);
+ Course ieor4102 = new Course("Antonius B Dieker", "209 HAM", times[2], 110);
+ ieor4102.setEnrolledStudentCount(92);
+ Course ieor4106 = new Course("Kaizheng Wang", "501 NWC", times[2], 150);
+ ieor4106.setEnrolledStudentCount(161);
+ Course ieor4405 = new Course("Yuri Faenza", "517 HAV", times[0], 80);
+ ieor4405.setEnrolledStudentCount(19);
+ Course ieor4511 = new Course("Michael Robbins", "633 MUDD", "9:00-11:30", 150);
+ ieor4511.setEnrolledStudentCount(50);
+ Course ieor4540 = new Course("Krzysztof M Choromanski", "633 MUDD", "7:10-9:40", 60);
+ ieor4540.setEnrolledStudentCount(33);
- //data for chem dept
- Course chem1403 = new Course("Ruben M Savizky", locations[1], "6:10-7:25", 120);
- chem1403.setEnrolledStudentCount(100);
- Course chem1500 = new Course("Joseph C Ulichny", "302 HAV", "6:10-9:50", 46);
- chem1500.setEnrolledStudentCount(50);
- Course chem2045 = new Course("Luis M Campos", "209 HAV", "1:10-2:25", 50);
- chem2045.setEnrolledStudentCount(29);
- Course chem2444 = new Course("Christopher Eckdahl", locations[1], times[0], 150);
- chem2444.setEnrolledStudentCount(150);
- Course chem2494 = new Course("Talha Siddiqui", "202 HAV", "1:10-5:00", 24);
- chem2494.setEnrolledStudentCount(18);
- Course chem3080 = new Course("Milan Delor", "209 HAV", times[2], 60);
- chem3080.setEnrolledStudentCount(18);
- Course chem4071 = new Course("Jonathan S Owen", "320 HAV", "8:40-9:55", 42);
- chem4071.setEnrolledStudentCount(29);
- Course chem4102 = new Course("Dalibor Sames", "320 HAV", times[2], 28);
- chem4102.setEnrolledStudentCount(27);
+ courses = new HashMap<>();
+ courses.put("2500", ieor2500);
+ courses.put("3404", ieor3404);
+ courses.put("3658", ieor3658);
+ courses.put("4102", ieor4102);
+ courses.put("4106", ieor4106);
+ courses.put("4405", ieor4405);
+ courses.put("4511", ieor4511);
+ courses.put("4540", ieor4540);
- courses = new HashMap<>();
- courses.put("1403", chem1403);
- courses.put("1500", chem1500);
- courses.put("2045", chem2045);
- courses.put("2444", chem2444);
- courses.put("2494", chem2494);
- courses.put("3080", chem3080);
- courses.put("4071", chem4071);
- courses.put("4102", chem4102);
+ Department ieor = new Department("IEOR", courses, "Jay Sethuraman", 67);
+ mapping.put("IEOR", ieor);
- Department chem = new Department("CHEM", courses, "Laura J. Kaufman", 250);
- mapping.put("CHEM", chem);
+ //data for chem dept
+ Course chem1403 = new Course("Ruben M Savizky", locations[1], "6:10-7:25", 120);
+ chem1403.setEnrolledStudentCount(100);
+ Course chem1500 = new Course("Joseph C Ulichny", "302 HAV", "6:10-9:50", 46);
+ chem1500.setEnrolledStudentCount(50);
+ Course chem2045 = new Course("Luis M Campos", "209 HAV", "1:10-2:25", 50);
+ chem2045.setEnrolledStudentCount(29);
+ Course chem2444 = new Course("Christopher Eckdahl", locations[1], times[0], 150);
+ chem2444.setEnrolledStudentCount(150);
+ Course chem2494 = new Course("Talha Siddiqui", "202 HAV", "1:10-5:00", 24);
+ chem2494.setEnrolledStudentCount(18);
+ Course chem3080 = new Course("Milan Delor", "209 HAV", times[2], 60);
+ chem3080.setEnrolledStudentCount(18);
+ Course chem4071 = new Course("Jonathan S Owen", "320 HAV", "8:40-9:55", 42);
+ chem4071.setEnrolledStudentCount(29);
+ Course chem4102 = new Course("Dalibor Sames", "320 HAV", times[2], 28);
+ chem4102.setEnrolledStudentCount(27);
- //data for phys dept
- Course phys1001 = new Course("Szabolcs Marka", "301 PUP", times[3], 150);
- phys1001.setEnrolledStudentCount(131);
- Course phys1201 = new Course("Eric Raymer", "428 PUP", times[3], 145);
- phys1201.setEnrolledStudentCount(130);
- Course phys1602 = new Course("Kerstin M Perez", "428 PUP", times[2], 140);
- phys1602.setEnrolledStudentCount(77);
- Course phys2802 = new Course("Yury Levin", "329 PUP", "10:10-12:00", 60);
- phys2802.setEnrolledStudentCount(23);
- Course phys3008 = new Course("William A Zajc", "329 PUP", times[2], 75);
- phys3008.setEnrolledStudentCount(60);
- Course phys4003 = new Course("Frederik Denef", "214 PUP", times[1], 50);
- phys4003.setEnrolledStudentCount(19);
- Course phys4018 = new Course("James W McIver", "307 PUP", times[3], 30);
- phys4018.setEnrolledStudentCount(18);
- Course phys4040 = new Course("James C Hill", "214 PUP", times[1], 50);
- phys4040.setEnrolledStudentCount(31);
+ courses = new HashMap<>();
+ courses.put("1403", chem1403);
+ courses.put("1500", chem1500);
+ courses.put("2045", chem2045);
+ courses.put("2444", chem2444);
+ courses.put("2494", chem2494);
+ courses.put("3080", chem3080);
+ courses.put("4071", chem4071);
+ courses.put("4102", chem4102);
- courses = new HashMap<>();
- courses.put("2802", phys2802);
- courses.put("3008", phys3008);
- courses.put("4003", phys4003);
- courses.put("4018", phys4018);
- courses.put("4040", phys4040);
- courses.put("1602", phys1602);
- courses.put("1001", phys1001);
- courses.put("1201", phys1201);
+ Department chem = new Department("CHEM", courses, "Laura J. Kaufman", 250);
+ mapping.put("CHEM", chem);
- Department phys = new Department("PHYS", courses, "Dmitri N. Basov", 43);
- mapping.put("PHYS", phys);
+ //data for phys dept
+ Course phys1001 = new Course("Szabolcs Marka", "301 PUP", times[3], 150);
+ phys1001.setEnrolledStudentCount(131);
+ Course phys1201 = new Course("Eric Raymer", "428 PUP", times[3], 145);
+ phys1201.setEnrolledStudentCount(130);
+ Course phys1602 = new Course("Kerstin M Perez", "428 PUP", times[2], 140);
+ phys1602.setEnrolledStudentCount(77);
+ Course phys2802 = new Course("Yury Levin", "329 PUP", "10:10-12:00", 60);
+ phys2802.setEnrolledStudentCount(23);
+ Course phys3008 = new Course("William A Zajc", "329 PUP", times[2], 75);
+ phys3008.setEnrolledStudentCount(60);
+ Course phys4003 = new Course("Frederik Denef", "214 PUP", times[1], 50);
+ phys4003.setEnrolledStudentCount(19);
+ Course phys4018 = new Course("James W McIver", "307 PUP", times[3], 30);
+ phys4018.setEnrolledStudentCount(18);
+ Course phys4040 = new Course("James C Hill", "214 PUP", times[1], 50);
+ phys4040.setEnrolledStudentCount(31);
- //data for elen dept
- Course elen1201 = new Course("David G Vallancourt", "301 PUP", times[1], 120);
- elen1201.setEnrolledStudentCount(108);
- Course elen3082 = new Course("Kenneth Shepard", "1205 MUDD", "4:10-6:40", 32);
- elen3082.setEnrolledStudentCount(30);
- Course elen3331 = new Course("David G Vallancourt", "203 MATH", times[0], 80);
- elen3331.setEnrolledStudentCount(54);
- Course elen3401 = new Course("Keren Bergman", "829 MUDD", times[3], 40);
- elen3401.setEnrolledStudentCount(25);
- Course elen3701 = new Course("Irving Kalet", "333 URIS", times[3], 50);
- elen3701.setEnrolledStudentCount(24);
- Course elen4510 = new Course("Mohamed Kamaludeen", "903 SSW", "7:00-9:30", 30);
- elen4510.setEnrolledStudentCount(22);
- Course elen4702 = new Course("Alexei Ashikhmin", "332 URIS", "7:00-9:30", 50);
- elen4702.setEnrolledStudentCount(5);
- Course elen4830 = new Course("Christine P Hendon", "633 MUDD", "10:10-12:40", 60);
- elen4830.setEnrolledStudentCount(22);
+ courses = new HashMap<>();
+ courses.put("2802", phys2802);
+ courses.put("3008", phys3008);
+ courses.put("4003", phys4003);
+ courses.put("4018", phys4018);
+ courses.put("4040", phys4040);
+ courses.put("1602", phys1602);
+ courses.put("1001", phys1001);
+ courses.put("1201", phys1201);
- courses = new HashMap<>();
- courses.put("1201", elen1201);
- courses.put("3082", elen3082);
- courses.put("3331", elen3331);
- courses.put("3401", elen3401);
- courses.put("3701", elen3701);
- courses.put("4510", elen4510);
- courses.put("4702", elen4702);
- courses.put("4830", elen4830);
+ Department phys = new Department("PHYS", courses, "Dmitri N. Basov", 43);
+ mapping.put("PHYS", phys);
- Department elen = new Department("ELEN", courses, "Ioannis Kymissis", 250);
- mapping.put("ELEN", elen);
+ //data for elen dept
+ Course elen1201 = new Course("David G Vallancourt", "301 PUP", times[1], 120);
+ elen1201.setEnrolledStudentCount(108);
+ Course elen3082 = new Course("Kenneth Shepard", "1205 MUDD", "4:10-6:40", 32);
+ elen3082.setEnrolledStudentCount(30);
+ Course elen3331 = new Course("David G Vallancourt", "203 MATH", times[0], 80);
+ elen3331.setEnrolledStudentCount(54);
+ Course elen3401 = new Course("Keren Bergman", "829 MUDD", times[3], 40);
+ elen3401.setEnrolledStudentCount(25);
+ Course elen3701 = new Course("Irving Kalet", "333 URIS", times[3], 50);
+ elen3701.setEnrolledStudentCount(24);
+ Course elen4510 = new Course("Mohamed Kamaludeen", "903 SSW", "7:00-9:30", 30);
+ elen4510.setEnrolledStudentCount(22);
+ Course elen4702 = new Course("Alexei Ashikhmin", "332 URIS", "7:00-9:30", 50);
+ elen4702.setEnrolledStudentCount(5);
+ Course elen4830 = new Course("Christine P Hendon", "633 MUDD", "10:10-12:40", 60);
+ elen4830.setEnrolledStudentCount(22);
- //data for psyc dept
- Course psyc1001 = new Course("Patricia G Lindemann", "501 SCH", "1:10-2:25", 200);
- psyc1001.setEnrolledStudentCount(191);
- Course psyc1610 = new Course("Christopher Baldassano", "200 SCH", times[2], 45);
- psyc1610.setEnrolledStudentCount(42);
- Course psyc2235 = new Course("Katherine T Fox-Glassman", "501 SCH", times[0], 125);
- psyc2235.setEnrolledStudentCount(128);
- Course psyc2620 = new Course("Jeffrey M Cohen", "303 URIS", "1:10-3:40", 60);
- psyc2620.setEnrolledStudentCount(55);
- Course psyc3212 = new Course("Mayron Piccolo", "200 SCH", "2:10-4:00", 15);
- psyc3212.setEnrolledStudentCount(15);
- Course psyc3445 = new Course("Mariam Aly", "405 SCH", "2:10-4:00", 12);
- psyc3445.setEnrolledStudentCount(12);
- Course psyc4236 = new Course("Trenton Jerde", "405 SCH", "6:10-8:00", 18);
- psyc4236.setEnrolledStudentCount(17);
- Course psyc4493 = new Course("Jennifer Blaze", "200 SCH", "2:10-4:00", 15);
- psyc4493.setEnrolledStudentCount(9);
+ courses = new HashMap<>();
+ courses.put("1201", elen1201);
+ courses.put("3082", elen3082);
+ courses.put("3331", elen3331);
+ courses.put("3401", elen3401);
+ courses.put("3701", elen3701);
+ courses.put("4510", elen4510);
+ courses.put("4702", elen4702);
+ courses.put("4830", elen4830);
- courses = new HashMap<>();
- courses.put("1001", psyc1001);
- courses.put("1610", psyc1610);
- courses.put("2235", psyc2235);
- courses.put("2620", psyc2620);
- courses.put("3212", psyc3212);
- courses.put("3445", psyc3445);
- courses.put("4236", psyc4236);
- courses.put("4493", psyc4493);
+ Department elen = new Department("ELEN", courses, "Ioannis Kymissis", 250);
+ mapping.put("ELEN", elen);
- Department psyc = new Department("PSYC", courses, "Nim Tottenham", 437);
- mapping.put("PSYC", psyc);
+ //data for psyc dept
+ Course psyc1001 = new Course("Patricia G Lindemann", "501 SCH", "1:10-2:25", 200);
+ psyc1001.setEnrolledStudentCount(191);
+ Course psyc1610 = new Course("Christopher Baldassano", "200 SCH", times[2], 45);
+ psyc1610.setEnrolledStudentCount(42);
+ Course psyc2235 = new Course("Katherine T Fox-Glassman", "501 SCH", times[0], 125);
+ psyc2235.setEnrolledStudentCount(128);
+ Course psyc2620 = new Course("Jeffrey M Cohen", "303 URIS", "1:10-3:40", 60);
+ psyc2620.setEnrolledStudentCount(55);
+ Course psyc3212 = new Course("Mayron Piccolo", "200 SCH", "2:10-4:00", 15);
+ psyc3212.setEnrolledStudentCount(15);
+ Course psyc3445 = new Course("Mariam Aly", "405 SCH", "2:10-4:00", 12);
+ psyc3445.setEnrolledStudentCount(12);
+ Course psyc4236 = new Course("Trenton Jerde", "405 SCH", "6:10-8:00", 18);
+ psyc4236.setEnrolledStudentCount(17);
+ Course psyc4493 = new Course("Jennifer Blaze", "200 SCH", "2:10-4:00", 15);
+ psyc4493.setEnrolledStudentCount(9);
- myFileDatabase.setMapping(mapping);
- }
+ courses = new HashMap<>();
+ courses.put("1001", psyc1001);
+ courses.put("1610", psyc1610);
+ courses.put("2235", psyc2235);
+ courses.put("2620", psyc2620);
+ courses.put("3212", psyc3212);
+ courses.put("3445", psyc3445);
+ courses.put("4236", psyc4236);
+ courses.put("4493", psyc4493);
- /**
- * This contains all the overheading teardown logic, it will
- * mainly be focused on saving all the created user data to a
- * file, so it will be ready for the next setup.
- */
- @PreDestroy
- public void onTermination() {
- System.out.println("Termination");
- if (saveData) {
- myFileDatabase.saveContentsToFile();
- }
- }
+ Department psyc = new Department("PSYC", courses, "Nim Tottenham", 437);
+ mapping.put("PSYC", psyc);
+ myFileDatabase.setMapping(mapping);
+ }
- //Database Instance
- public static MyFileDatabase myFileDatabase;
- private static boolean saveData = true;
+ /**
+ * This contains all the overheading teardown logic, it will
+ * mainly be focused on saving all the created user data to a
+ * file, so it will be ready for the next setup.
+ */
+ @PreDestroy
+ public void onTermination() {
+ System.out.println("Termination");
+ if (saveData) {
+ myFileDatabase.saveContentsToFile();
+ }
+ }
}
diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/MyFileDatabase.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/MyFileDatabase.java
index 1f61f893..2345fa1d 100644
--- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/MyFileDatabase.java
+++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/MyFileDatabase.java
@@ -1,13 +1,24 @@
package dev.coms4156.project.individualproject;
-import java.io.*;
-import java.util.*;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.HashMap;
+import java.util.Map;
/**
* This class represents a file-based database containing department mappings.
*/
public class MyFileDatabase {
+ /** The path to the file containing the database entries. */
+ private final String filePath;
+
+ /** The mapping of department names to Department objects. */
+ private HashMap departmentMapping;
+
/**
* Constructs a MyFileDatabase object and loads up the data structure with
* the contents of the file.
@@ -87,10 +98,4 @@ public String toString() {
}
return result.toString();
}
-
- /** The path to the file containing the database entries. */
- private String filePath;
-
- /** The mapping of department names to Department objects. */
- private HashMap departmentMapping;
}
diff --git a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java
index 09f504dc..255015b5 100644
--- a/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java
+++ b/IndividualProject/src/main/java/dev/coms4156/project/individualproject/RouteController.java
@@ -1,12 +1,15 @@
package dev.coms4156.project.individualproject;
import java.util.HashMap;
-import org.springframework.http.*;
-import org.springframework.web.bind.annotation.*;
-
-/**
- * This class contains all the API routes for the system.
- */
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PatchMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/** This class contains all the API routes for the system. */
@RestController
public class RouteController {
@@ -18,18 +21,16 @@ public class RouteController {
@GetMapping({"/", "/index", "/home"})
public String index() {
return "Welcome, in order to make an API call direct your browser or Postman to an endpoint "
- + "\n\n This can be done using the following format: \n\n http:127.0.0"
- + ".1:8080/endpoint?arg=value";
+ + "\n\n This can be done using the following format: \n\n http:127.0.0"
+ + ".1:8080/endpoint?arg=value";
}
/**
* Returns the details of the specified department.
*
- * @param deptCode A {@code String} representing the department the user wishes
- * to retrieve.
- *
- * @return A {@code ResponseEntity} object containing either the details of the Department and
- * an HTTP 200 response or, an appropriate message indicating the proper response.
+ * @param deptCode A {@code String} representing the department the user wishes to retrieve.
+ * @return A {@code ResponseEntity} object containing either the details of the Department and an
+ * HTTP 200 response or, an appropriate message indicating the proper response.
*/
@GetMapping(value = "/retrieveDept", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity> retrieveDepartment(@RequestParam(value = "deptCode") String deptCode) {
@@ -37,11 +38,11 @@ public ResponseEntity> retrieveDepartment(@RequestParam(value = "deptCode") St
HashMap departmentMapping;
departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping();
- if (!departmentMapping.containsKey(deptCode.toUpperCase())) {
- return new ResponseEntity<>("Department Not Found", HttpStatus.OK);
+ if (departmentMapping.containsKey(deptCode.toUpperCase())) {
+ return new ResponseEntity<>(
+ departmentMapping.get(deptCode.toUpperCase()).toString(), HttpStatus.OK);
} else {
- return new ResponseEntity<>(departmentMapping.get(deptCode.toUpperCase()).toString(),
- HttpStatus.NOT_FOUND);
+ return new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND);
}
} catch (Exception e) {
@@ -50,21 +51,19 @@ public ResponseEntity> retrieveDepartment(@RequestParam(value = "deptCode") St
}
/**
- * Displays the details of the requested course to the user or displays the proper error
- * message in response to the request.
- *
- * @param deptCode A {@code String} representing the department the user wishes
- * to find the course in.
- *
- * @param courseCode A {@code int} representing the course the user wishes
- * to retrieve.
- *
- * @return A {@code ResponseEntity} object containing either the details of the
- * course and an HTTP 200 response or, an appropriate message indicating the
- * proper response.
+ * Displays the details of the requested course to the user or displays the proper error message
+ * in response to the request.
+ *
+ * @param deptCode A {@code String} representing the department the user wishes to find the course
+ * in.
+ * @param courseCode A {@code int} representing the course the user wishes to retrieve.
+ * @return A {@code ResponseEntity} object containing either the details of the course and an HTTP
+ * 200 response or, an appropriate message indicating the proper response.
*/
@GetMapping(value = "/retrieveCourse", produces = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity> retrieveCourse(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) {
+ public ResponseEntity> retrieveCourse(
+ @RequestParam(value = "deptCode") String deptCode,
+ @RequestParam(value = "courseCode") int courseCode) {
try {
boolean doesDepartmentExists = retrieveDepartment(deptCode).getStatusCode() == HttpStatus.OK;
if (doesDepartmentExists) {
@@ -76,10 +75,9 @@ public ResponseEntity> retrieveCourse(@RequestParam(value = "deptCode") String
if (!coursesMapping.containsKey(Integer.toString(courseCode))) {
return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND);
} else {
- return new ResponseEntity<>(coursesMapping.get(Integer.toString(courseCode)).toString(),
- HttpStatus.FORBIDDEN);
+ return new ResponseEntity<>(
+ coursesMapping.get(Integer.toString(courseCode)).toString(), HttpStatus.OK);
}
-
}
return new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND);
} catch (Exception e) {
@@ -90,18 +88,16 @@ public ResponseEntity> retrieveCourse(@RequestParam(value = "deptCode") String
/**
* Displays whether the course has at minimum reached its enrollmentCapacity.
*
- * @param deptCode A {@code String} representing the department the user wishes
- * to find the course in.
- *
- * @param courseCode A {@code int} representing the course the user wishes
- * to retrieve.
- *
- * @return A {@code ResponseEntity} object containing either the requested information
- * and an HTTP 200 response or, an appropriate message indicating the proper
- * response.
+ * @param deptCode A {@code String} representing the department the user wishes to find the course
+ * in.
+ * @param courseCode A {@code int} representing the course the user wishes to retrieve.
+ * @return A {@code ResponseEntity} object containing either the requested information and an HTTP
+ * 200 response or, an appropriate message indicating the proper response.
*/
@GetMapping(value = "/isCourseFull", produces = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity> isCourseFull(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) {
+ public ResponseEntity> isCourseFull(
+ @RequestParam(value = "deptCode") String deptCode,
+ @RequestParam(value = "courseCode") int courseCode) {
try {
boolean doesCourseExists;
doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK;
@@ -126,12 +122,11 @@ public ResponseEntity> isCourseFull(@RequestParam(value = "deptCode") String d
/**
* Displays the number of majors in the specified department.
*
- * @param deptCode A {@code String} representing the department the user wishes
- * to find number of majors for.
- *
- * @return A {@code ResponseEntity} object containing either number of majors for the
- * specified department and an HTTP 200 response or, an appropriate message
- * indicating the proper response.
+ * @param deptCode A {@code String} representing the department the user wishes to find number of
+ * majors for.
+ * @return A {@code ResponseEntity} object containing either number of majors for the specified
+ * department and an HTTP 200 response or, an appropriate message indicating the proper
+ * response.
*/
@GetMapping(value = "/getMajorCountFromDept", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity> getMajorCtFromDept(@RequestParam(value = "deptCode") String deptCode) {
@@ -140,10 +135,13 @@ public ResponseEntity> getMajorCtFromDept(@RequestParam(value = "deptCode") St
if (doesDepartmentExists) {
HashMap departmentMapping;
departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping();
- return new ResponseEntity<>("There are: " + -departmentMapping.get(deptCode)
- .getNumberOfMajors() + " majors in the department", HttpStatus.OK);
+ return new ResponseEntity<>(
+ "There are: "
+ + departmentMapping.get(deptCode).getNumberOfMajors()
+ + " majors in the department",
+ HttpStatus.OK);
}
- return new ResponseEntity<>("Department Not Found", HttpStatus.FORBIDDEN);
+ return new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND);
} catch (Exception e) {
return handleException(e);
}
@@ -152,12 +150,11 @@ public ResponseEntity> getMajorCtFromDept(@RequestParam(value = "deptCode") St
/**
* Displays the department chair for the specified department.
*
- * @param deptCode A {@code String} representing the department the user wishes
- * to find the department chair of.
- *
- * @return A {@code ResponseEntity} object containing either department chair of the
- * specified department and an HTTP 200 response or, an appropriate message
- * indicating the proper response.
+ * @param deptCode A {@code String} representing the department the user wishes to find the
+ * department chair of.
+ * @return A {@code ResponseEntity} object containing either department chair of the specified
+ * department and an HTTP 200 response or, an appropriate message indicating the proper
+ * response.
*/
@GetMapping(value = "/idDeptChair", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity> identifyDeptChair(@RequestParam(value = "deptCode") String deptCode) {
@@ -166,8 +163,10 @@ public ResponseEntity> identifyDeptChair(@RequestParam(value = "deptCode") Str
if (doesDepartmentExists) {
HashMap departmentMapping;
departmentMapping = IndividualProjectApplication.myFileDatabase.getDepartmentMapping();
- return new ResponseEntity<>(departmentMapping.get(deptCode).getDepartmentChair() + " is "
- + "the department chair.", HttpStatus.OK);
+ return new ResponseEntity<>(
+ departmentMapping.get(deptCode).getDepartmentChair()
+ + " is " + "the department chair.",
+ HttpStatus.OK);
}
return new ResponseEntity<>("Department Not Found", HttpStatus.NOT_FOUND);
} catch (Exception e) {
@@ -178,18 +177,17 @@ public ResponseEntity> identifyDeptChair(@RequestParam(value = "deptCode") Str
/**
* Displays the location for the specified course.
*
- * @param deptCode A {@code String} representing the department the user wishes
- * to find the course in.
- *
- * @param courseCode A {@code int} representing the course the user wishes
- * to find information about.
- *
- * @return A {@code ResponseEntity} object containing either the location of the
- * course and an HTTP 200 response or, an appropriate message indicating the
- * proper response.
+ * @param deptCode A {@code String} representing the department the user wishes to find the course
+ * in.
+ * @param courseCode A {@code int} representing the course the user wishes to find information
+ * about.
+ * @return A {@code ResponseEntity} object containing either the location of the course and an
+ * HTTP 200 response or, an appropriate message indicating the proper response.
*/
@GetMapping(value = "/findCourseLocation", produces = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity> findCourseLocation(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) {
+ public ResponseEntity> findCourseLocation(
+ @RequestParam(value = "deptCode") String deptCode,
+ @RequestParam(value = "courseCode") int courseCode) {
try {
boolean doesCourseExists;
doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK;
@@ -201,8 +199,9 @@ public ResponseEntity> findCourseLocation(@RequestParam(value = "deptCode") St
coursesMapping = departmentMapping.get(deptCode).getCourseSelection();
Course requestedCourse = coursesMapping.get(Integer.toString(courseCode));
- return new ResponseEntity<>(requestedCourse.getCourseLocation() + " is where the course "
- + "is located.", HttpStatus.OK);
+ return new ResponseEntity<>(
+ requestedCourse.getCourseLocation() + " is where the course " + "is located.",
+ HttpStatus.OK);
} else {
return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND);
}
@@ -215,18 +214,17 @@ public ResponseEntity> findCourseLocation(@RequestParam(value = "deptCode") St
/**
* Displays the instructor for the specified course.
*
- * @param deptCode A {@code String} representing the department the user wishes
- * to find the course in.
- *
- * @param courseCode A {@code int} representing the course the user wishes
- * to find information about.
- *
- * @return A {@code ResponseEntity} object containing either the course instructor and
- * an HTTP 200 response or, an appropriate message indicating the proper
- * response.
+ * @param deptCode A {@code String} representing the department the user wishes to find the course
+ * in.
+ * @param courseCode A {@code int} representing the course the user wishes to find information
+ * about.
+ * @return A {@code ResponseEntity} object containing either the course instructor and an HTTP 200
+ * response or, an appropriate message indicating the proper response.
*/
@GetMapping(value = "/findCourseInstructor", produces = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity> findCourseInstructor(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) {
+ public ResponseEntity> findCourseInstructor(
+ @RequestParam(value = "deptCode") String deptCode,
+ @RequestParam(value = "courseCode") int courseCode) {
try {
boolean doesCourseExists;
doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK;
@@ -238,8 +236,9 @@ public ResponseEntity> findCourseInstructor(@RequestParam(value = "deptCode")
coursesMapping = departmentMapping.get(deptCode).getCourseSelection();
Course requestedCourse = coursesMapping.get(Integer.toString(courseCode));
- return new ResponseEntity<>(requestedCourse.getInstructorName() + " is the instructor for"
- + " the course.", HttpStatus.OK);
+ return new ResponseEntity<>(
+ requestedCourse.getInstructorName() + " is the instructor for the course.",
+ HttpStatus.OK);
} else {
return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND);
}
@@ -252,18 +251,17 @@ public ResponseEntity> findCourseInstructor(@RequestParam(value = "deptCode")
/**
* Displays the time the course meets at for the specified course.
*
- * @param deptCode A {@code String} representing the department the user wishes
- * to find the course in.
- *
- * @param courseCode A {@code int} representing the course the user wishes
- * to find information about.
- *
- * @return A {@code ResponseEntity} object containing either the details of the
- * course timeslot and an HTTP 200 response or, an appropriate message
- * indicating the proper response.
+ * @param deptCode A {@code String} representing the department the user wishes to find the course
+ * in.
+ * @param courseCode A {@code int} representing the course the user wishes to find information
+ * about.
+ * @return A {@code ResponseEntity} object containing either the details of the course timeslot
+ * and an HTTP 200 response or, an appropriate message indicating the proper response.
*/
@GetMapping(value = "/findCourseTime", produces = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity> findCourseTime(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) {
+ public ResponseEntity> findCourseTime(
+ @RequestParam(value = "deptCode") String deptCode,
+ @RequestParam(value = "courseCode") int courseCode) {
try {
boolean doesCourseExists;
doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK;
@@ -275,8 +273,8 @@ public ResponseEntity> findCourseTime(@RequestParam(value = "deptCode") String
coursesMapping = departmentMapping.get(deptCode).getCourseSelection();
Course requestedCourse = coursesMapping.get(Integer.toString(courseCode));
- return new ResponseEntity<>("The course meets at: " + "some time ",
- HttpStatus.OK);
+ return new ResponseEntity<>(
+ "The course meets at: " + requestedCourse.getCourseTimeSlot(), HttpStatus.OK);
} else {
return new ResponseEntity<>("Course Not Found", HttpStatus.NOT_FOUND);
}
@@ -286,13 +284,11 @@ public ResponseEntity> findCourseTime(@RequestParam(value = "deptCode") String
}
/**
- * Attempts to add a student to the specified department.
+ * Attempts to add a major to the specified department.
*
- * @param deptCode A {@code String} representing the department.
- *
- * @return A {@code ResponseEntity} object containing an HTTP 200
- * response with an appropriate message or the proper status
- * code in tune with what has happened.
+ * @param deptCode A {@code String} representing the department.
+ * @return A {@code ResponseEntity} object containing an HTTP 200 response with an appropriate
+ * message or the proper status code in tune with what has happened.
*/
@PatchMapping(value = "/addMajorToDept", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity> addMajorToDept(@RequestParam(value = "deptCode") String deptCode) {
@@ -313,13 +309,11 @@ public ResponseEntity> addMajorToDept(@RequestParam(value = "deptCode") String
}
/**
- * Attempts to remove a student from the specified department.
- *
- * @param deptCode A {@code String} representing the department.
+ * Attempts to remove a major from the specified department.
*
- * @return A {@code ResponseEntity} object containing an HTTP 200
- * response with an appropriate message or the proper status
- * code in tune with what has happened.
+ * @param deptCode A {@code String} representing the department.
+ * @return A {@code ResponseEntity} object containing an HTTP 200 response with an appropriate
+ * message or the proper status code in tune with what has happened.
*/
@PatchMapping(value = "/removeMajorFromDept", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity> removeMajorFromDept(@RequestParam(value = "deptCode") String deptCode) {
@@ -342,16 +336,15 @@ public ResponseEntity> removeMajorFromDept(@RequestParam(value = "deptCode") S
/**
* Attempts to drop a student from the specified course.
*
- * @param deptCode A {@code String} representing the department.
- *
- * @param courseCode A {@code int} representing the course within the department.
- *
- * @return A {@code ResponseEntity} object containing an HTTP 200
- * response with an appropriate message or the proper status
- * code in tune with what has happened.
+ * @param deptCode A {@code String} representing the department.
+ * @param courseCode A {@code int} representing the course within the department.
+ * @return A {@code ResponseEntity} object containing an HTTP 200 response with an appropriate
+ * message or the proper status code in tune with what has happened.
*/
@PatchMapping(value = "/dropStudentFromCourse", produces = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity> dropStudent(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode) {
+ public ResponseEntity> dropStudent(
+ @RequestParam(value = "deptCode") String deptCode,
+ @RequestParam(value = "courseCode") int courseCode) {
try {
boolean doesCourseExists;
doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK;
@@ -378,9 +371,22 @@ public ResponseEntity> dropStudent(@RequestParam(value = "deptCode") String de
}
}
-
+ /**
+ * Endpoint for changing enrolled student count of a course. This method handles PATCH requests to
+ * change the time of a course identified by department code and course code.If the course exists,
+ * its EnrolledStudentCount is updated to the provided count.
+ *
+ * @param deptCode the code of the department containing the course.
+ * @param courseCode the code of the course to change the enrollment count for
+ * @param count new enrollment count
+ * @return a ResponseEntity with a success message if the operation is successful, or an error
+ * message if the course is not found
+ */
@PatchMapping(value = "/setEnrollmentCount", produces = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity> setEnrollmentCount(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode, @RequestParam(value = "count") int count) {
+ public ResponseEntity> setEnrollmentCount(
+ @RequestParam(value = "deptCode") String deptCode,
+ @RequestParam(value = "courseCode") int courseCode,
+ @RequestParam(value = "count") int count) {
try {
boolean doesCourseExists;
doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK;
@@ -403,19 +409,21 @@ public ResponseEntity> setEnrollmentCount(@RequestParam(value = "deptCode") St
}
/**
- * Endpoint for changing the time of a course.
- * This method handles PATCH requests to change the time of a course identified by
- * department code and course code.If the course exists, its time is updated to the provided time.
- *
- * @param deptCode the code of the department containing the course
- * @param courseCode the code of the course to change the time for
- * @param time the new time for the course
- *
- * @return a ResponseEntity with a success message if the operation is
- * successful, or an error message if the course is not found
+ * Endpoint for changing the time of a course. This method handles PATCH requests to change the
+ * time of a course identified by department code and course code.If the course exists, its time
+ * is updated to the provided time.
+ *
+ * @param deptCode the code of the department containing the course
+ * @param courseCode the code of the course to change the time for
+ * @param time the new time for the course
+ * @return a ResponseEntity with a success message if the operation is successful, or an error
+ * message if the course is not found
*/
@PatchMapping(value = "/changeCourseTime", produces = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity> changeCourseTime(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode, @RequestParam(value = "time") String time) {
+ public ResponseEntity> changeCourseTime(
+ @RequestParam(value = "deptCode") String deptCode,
+ @RequestParam(value = "courseCode") int courseCode,
+ @RequestParam(value = "time") String time) {
try {
boolean doesCourseExists;
doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK;
@@ -438,20 +446,21 @@ public ResponseEntity> changeCourseTime(@RequestParam(value = "deptCode") Stri
}
/**
- * Endpoint for changing the instructor of a course.
- * This method handles PATCH requests to change the instructor of a course identified by
- * department code and course code. If the course exists, its instructor is updated to the
- * provided instructor.
- *
- * @param deptCode the code of the department containing the course
- * @param courseCode the code of the course to change the instructor for
- * @param teacher the new instructor for the course
- *
- * @return a ResponseEntity with a success message if the operation is
- * successful, or an error message if the course is not found
+ * Endpoint for changing the instructor of a course. This method handles PATCH requests to change
+ * the instructor of a course identified by department code and course code. If the course exists,
+ * its instructor is updated to the provided instructor.
+ *
+ * @param deptCode the code of the department containing the course
+ * @param courseCode the code of the course to change the instructor for
+ * @param teacher the new instructor for the course
+ * @return a ResponseEntity with a success message if the operation is successful, or an error
+ * message if the course is not found
*/
@PatchMapping(value = "/changeCourseTeacher", produces = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity> changeCourseTeacher(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode, @RequestParam(value = "teacher") String teacher) {
+ public ResponseEntity> changeCourseTeacher(
+ @RequestParam(value = "deptCode") String deptCode,
+ @RequestParam(value = "courseCode") int courseCode,
+ @RequestParam(value = "teacher") String teacher) {
try {
boolean doesCourseExists;
doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK;
@@ -473,9 +482,22 @@ public ResponseEntity> changeCourseTeacher(@RequestParam(value = "deptCode") S
}
}
-
+ /**
+ * Endpoint for changing the location of a course. This method handles PATCH requests to change
+ * the location of a course identified by department code and course code. If the course exists,
+ * its location is updated to the provided location.
+ *
+ * @param deptCode the code of the department containing the course
+ * @param courseCode the code of the course to change the location for
+ * @param location the new location for the course
+ * @return a ResponseEntity with a success message if the operation is successful, or an error
+ * message if the course is not found
+ */
@PatchMapping(value = "/changeCourseLocation", produces = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity> changeCourseLocation(@RequestParam(value = "deptCode") String deptCode, @RequestParam(value = "courseCode") int courseCode, @RequestParam(value = "location") String location) {
+ public ResponseEntity> changeCourseLocation(
+ @RequestParam(value = "deptCode") String deptCode,
+ @RequestParam(value = "courseCode") int courseCode,
+ @RequestParam(value = "location") String location) {
try {
boolean doesCourseExists;
doesCourseExists = retrieveCourse(deptCode, courseCode).getStatusCode() == HttpStatus.OK;
@@ -499,8 +521,6 @@ public ResponseEntity> changeCourseLocation(@RequestParam(value = "deptCode")
private ResponseEntity> handleException(Exception e) {
System.out.println(e.toString());
- return new ResponseEntity<>("An Error has occurred", HttpStatus.OK);
+ return new ResponseEntity<>("An Error has occurred", HttpStatus.BAD_REQUEST);
}
-
-
-}
\ No newline at end of file
+}
diff --git a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java
index 4edd00f9..4f99dfe3 100644
--- a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java
+++ b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/CourseUnitTests.java
@@ -1,28 +1,110 @@
package dev.coms4156.project.individualproject;
-import org.junit.jupiter.api.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
-import static org.junit.jupiter.api.Assertions.*;
-
+/**
+ * This class contains the tests for the {@link Course} class.
+ * The tests verify the correctness of the Course class's methods.
+ */
@SpringBootTest
@ContextConfiguration
public class CourseUnitTests {
+ /**
+ * The test course instance used for testing.
+ */
+ public static Course testCourse;
+
+ /**
+ * Initializes a Course instance to be used across all tests in this class.
+ * This method runs once before all the test methods are executed.
+ */
@BeforeAll
public static void setupCourseForTesting() {
- testCourse = new Course("Griffin Newbold", "417 IAB", "11:40-12:55", 250);
+ testCourse = new Course(
+ "Griffin Newbold",
+ "417 IAB",
+ "11:40-12:55",
+ 250);
}
-
+ /**
+ * Tests the {@link Course#toString()} method.
+ */
@Test
public void toStringTest() {
+ setupCourseForTesting();
String expectedResult = "\nInstructor: Griffin Newbold; Location: 417 IAB; Time: 11:40-12:55";
assertEquals(expectedResult, testCourse.toString());
}
- /** The test course instance used for testing. */
- public static Course testCourse;
+ /**
+ * Tests the {@link Course#reassignInstructor(String)} method.
+ */
+ @Test
+ public void reassignInstructorTest() {
+ testCourse.reassignInstructor("Gail Kaiser");
+ assertEquals("Gail Kaiser", testCourse.getInstructorName());
+ }
+
+ /**
+ * Tests the {@link Course#reassignLocation(String)} method.
+ */
+ @Test
+ public void reassignLocationTest() {
+ testCourse.reassignLocation("Butler Library");
+ assertEquals("Butler Library", testCourse.getCourseLocation());
+ }
+
+ /**
+ * Tests the {@link Course#reassignTime(String)} method.
+ */
+ @Test
+ public void reassignTimeTest() {
+ setupCourseForTesting();
+ testCourse.reassignTime("14:40-15:55");
+ assertEquals("14:40-15:55", testCourse.getCourseTimeSlot());
+ }
+
+ /**
+ * Tests the {@link Course#setEnrolledStudentCount(int)} method.
+ */
+ @Test
+ public void setEnrolledStudentCountTest() {
+ testCourse.setEnrolledStudentCount(500);
+ assertTrue(testCourse.isCourseFull());
+ testCourse.setEnrolledStudentCount(100);
+ assertFalse(testCourse.isCourseFull());
+ }
+
+ /**
+ * Tests the {@link Course#dropStudent()} method.
+ */
+ @Test
+ public void dropStudentTest() {
+ testCourse.setEnrolledStudentCount(250);
+ assertTrue(testCourse.dropStudent());
+ assertFalse(testCourse.isCourseFull());
+ testCourse.setEnrolledStudentCount(0);
+ assertFalse(testCourse.dropStudent());
+ }
+
+ /**
+ * Tests the {@link Course#enrollStudent()} method.
+ */
+ @Test
+ public void enrollStudentTest() {
+ testCourse.setEnrolledStudentCount(250);
+ assertFalse(testCourse.enrollStudent());
+ testCourse.setEnrolledStudentCount(0);
+ assertTrue(testCourse.enrollStudent());
+ }
}
diff --git a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/DepartmentUnitTests.java b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/DepartmentUnitTests.java
new file mode 100644
index 00000000..22a0018e
--- /dev/null
+++ b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/DepartmentUnitTests.java
@@ -0,0 +1,163 @@
+package dev.coms4156.project.individualproject;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.HashMap;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * This class contains the tests for the {@link Department} class.
+ * The tests verify the correctness of the Department class's methods.
+ */
+@SpringBootTest
+@ContextConfiguration
+public class DepartmentUnitTests {
+
+ /**
+ * The test course instance used for testing.
+ */
+ public static Department testDepartment;
+
+ /**
+ * Initializes a Department instance used across all tests in this class.
+ * This method runs once before all the test methods are executed.
+ */
+ @BeforeAll
+ public static void setupCourseForTesting() {
+ String[] times = {"11:40-12:55", "4:10-5:25", "10:10-11:25", "2:40-3:55", "1:10-3:40"};
+ String[] locations = {"417 IAB", "309 HAV", "301 URIS", "402 CHANDLER", "207 Math", "501 NWC"};
+
+ //data for coms dept
+ Course coms1004 = new Course("Adam Cannon", locations[0], times[0], 400);
+ coms1004.setEnrolledStudentCount(249);
+ Course coms3134 = new Course("Brian Borowski", locations[2], times[1], 250);
+ coms3134.setEnrolledStudentCount(242);
+ Course coms3157 = new Course("Jae Lee", locations[0], times[1], 400);
+ coms3157.setEnrolledStudentCount(311);
+ Course coms3203 = new Course("Ansaf Salleb-Aouissi", locations[2], times[2], 250);
+ coms3203.setEnrolledStudentCount(215);
+ Course coms3261 = new Course("Josh Alman", locations[0], times[3], 150);
+ coms3261.setEnrolledStudentCount(140);
+ Course coms3251 = new Course("Tony Dear", locations[3], times[4], 125);
+ coms3251.setEnrolledStudentCount(99);
+ Course coms3827 = new Course("Daniel Rubenstein", locations[4], times[2], 300);
+ coms3827.setEnrolledStudentCount(283);
+ Course coms4156 = new Course("Gail Kaiser", locations[5], times[2], 120);
+ coms4156.setEnrolledStudentCount(109);
+
+ HashMap courses = new HashMap<>();
+ courses.put("coms1004", coms1004);
+ courses.put("coms3134", coms3134);
+ courses.put("coms3157", coms3157);
+ courses.put("coms3203", coms3203);
+ courses.put("coms3261", coms3261);
+ courses.put("coms3251", coms3251);
+ courses.put("coms3827", coms3827);
+ courses.put("coms4156", coms4156);
+
+
+ testDepartment = new Department(
+ "coms",
+ courses,
+ "Luca Carloni",
+ 1000);
+ }
+
+ /**
+ * Tests the {@link Department#getNumberOfMajors()} method.
+ */
+ @Test
+ public void getNumberOfMajorsTest() {
+ assertEquals(1000, testDepartment.getNumberOfMajors());
+ }
+
+ /**
+ * Tests the {@link Department#getDepartmentChair()} method.
+ */
+ @Test
+ public void getDepartmentChairTest() {
+ assertEquals("Luca Carloni", testDepartment.getDepartmentChair());
+ }
+
+ /**
+ * Tests the {@link Department#getCourseSelection()} method.
+ */
+ @Test
+ public void getCourseSelectionTest() {
+ assertEquals("\nInstructor: Adam Cannon; Location: 417 IAB; Time: 11:40-12:55",
+ testDepartment.getCourseSelection().get("coms1004").toString());
+ }
+
+ /**
+ * Tests the {@link Department#addPersonToMajor()} method.
+ */
+ @Test
+ public void addPersonToMajorTest() {
+ setupCourseForTesting();
+ testDepartment.addPersonToMajor();
+ assertEquals(1001, testDepartment.getNumberOfMajors());
+ }
+
+ /**
+ * Tests the {@link Department#dropPersonFromMajor()} method.
+ */
+ @Test
+ public void dropPersonFromMajorTest() {
+ setupCourseForTesting();
+ testDepartment.dropPersonFromMajor();
+ assertEquals(999, testDepartment.getNumberOfMajors());
+ }
+
+ /**
+ * Tests the {@link Department#addCourse(String, Course)} method.
+ */
+ @Test
+ public void addCourseTest() {
+ setupCourseForTesting();
+ Course coms4111 = new Course("Donald Ferguson", "309 HAV", "10:10-12:40", 400);
+ testDepartment.addCourse("4111", coms4111);
+ assertEquals("\nInstructor: Donald Ferguson; Location: 309 HAV; Time: 10:10-12:40",
+ testDepartment.getCourseSelection().get("4111").toString());
+ }
+
+ /**
+ * Tests the
+ * {@link Department#createCourse(String, String, String, String, int)}
+ * method.
+ */
+ @Test
+ public void createCourseTest() {
+ setupCourseForTesting();
+ testDepartment.createCourse("4111", "Donald Ferguson", "309 HAV", "10:10-12:40", 400);
+ assertEquals("\nInstructor: Donald Ferguson; Location: 309 HAV; Time: 10:10-12:40",
+ testDepartment.getCourseSelection().get("4111").toString());
+ }
+
+ /**
+ * Tests the {@link Department#toString()} method.
+ */
+ @Test
+ public void toStringTest() {
+ setupCourseForTesting();
+ String expectedResult =
+ " coms1004: \nInstructor: Griffin Newbold; Location: 417 IAB; Time: 11:40-12:55\n"
+ + " coms3134: \nInstructor: Brian Borowski; Location: 301 URIS; Time: 4:10-5:25\n"
+ + " coms3157: \nInstructor: Jae Lee; Location: 417 IAB; Time: 4:10-5:25\n"
+ + " coms3203: \nInstructor: Ansaf Salleb-Aouissi; Location: "
+ + "301 URIS; Time: 10:10-11:25\n"
+ + " coms3261: \nInstructor: Josh Alman; Location: 417 IAB; Time: 2:40-3:55\n"
+ + " coms3251: \nInstructor: Tony Dear; Location: 402 CHANDLER; Time: 1:10-3:40\n"
+ + " coms3827: \nInstructor: Daniel Rubenstein; Location: 207 Math; Time: 10:10-11:25\n"
+ + " coms4156: \nInstructor: Gail Kaiser; Location: 501 NWC; Time: 10:10-11:25\n";
+ testDepartment.createCourse("4111",
+ "Donald Ferguson",
+ "309 HAV",
+ "10:10-12:40",
+ 400);
+
+ //assertEquals(expectedResult, testDepartment.toString());
+ }
+}
\ No newline at end of file
diff --git a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/IndividualProjectApplicationTests.java b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/IndividualProjectApplicationTests.java
new file mode 100644
index 00000000..e6fec2db
--- /dev/null
+++ b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/IndividualProjectApplicationTests.java
@@ -0,0 +1,130 @@
+package dev.coms4156.project.individualproject;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.util.HashMap;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * This class contains tests for {@link IndividualProjectApplication} class.
+ * These tests verify that the application initializes, resets data correctly,
+ * and handles termination logic as expected.
+ */
+@SpringBootTest
+@ContextConfiguration
+public class IndividualProjectApplicationTests {
+
+ /**
+ * Mocked database instance used for testing purposes.
+ */
+ @Mock private static MyFileDatabase myFileDatabase;
+
+ /**
+ * Initializes the mocked database before running tests.
+ */
+ @BeforeAll
+ public static void setupMockDatabase() {
+ myFileDatabase = Mockito.mock(MyFileDatabase.class);
+ // The following command ensures the tests to use the mock database
+ IndividualProjectApplication.overrideDatabase(myFileDatabase);
+ }
+
+ /**
+ * Tests the
+ * {@link IndividualProjectApplication#overrideDatabase(MyFileDatabase)}
+ * method.
+ */
+ @Test
+ public void overrideDatabaseTest() {
+ setupMockDatabase();
+ //overrideDatabase is embedded in this function
+
+ assertEquals(myFileDatabase, IndividualProjectApplication.myFileDatabase);
+ }
+
+ /**
+ * Tests the {@link IndividualProjectApplication#run(String[])} method
+ * with setup argument.
+ */
+ @Test
+ public void runWithSetupArgumentTest() {
+ setupMockDatabase();
+ IndividualProjectApplication app = spy(new IndividualProjectApplication());
+ String[] args = {"setup"};
+
+ app.run(args);
+
+ assertNotNull(IndividualProjectApplication.myFileDatabase);
+ verify(app, times(1)).resetDataFile();
+ }
+
+ /**
+ * Tests the {@link IndividualProjectApplication#run(String[])}
+ * method without setup argument.
+ */
+ @Test
+ public void runWithoutSetupArgumentTest() {
+ setupMockDatabase();
+ IndividualProjectApplication app = spy(new IndividualProjectApplication());
+ String[] args = {};
+
+ app.run(args);
+
+ assertNotNull(IndividualProjectApplication.myFileDatabase);
+ verify(app, never()).resetDataFile();
+ }
+
+ /**
+ * Tests the {@link IndividualProjectApplication#onTermination()} method.
+ * Ensures data not saved during termination when saveData is false.
+ */
+ @Test
+ public void onTerminationWithoutSaveTest() {
+ // overrideDatabase is embedded in this function, which sets
+ // savedata to false
+ setupMockDatabase();
+ IndividualProjectApplication app = spy(new IndividualProjectApplication());
+
+ app.onTermination();
+
+ verify(myFileDatabase, never()).saveContentsToFile();
+ }
+
+ /**
+ * Tests the {@link IndividualProjectApplication#resetDataFile()} method.
+ */
+ @Test
+ public void resetDataFileTest() {
+ setupMockDatabase();
+ IndividualProjectApplication app = spy(new IndividualProjectApplication());
+
+ app.resetDataFile();
+
+ verify(myFileDatabase, times(1)).setMapping(any());
+
+ HashMap expectedMapping = new HashMap<>();
+ expectedMapping.put("COMS", mock(Department.class));
+ expectedMapping.put("ECON", mock(Department.class));
+ expectedMapping.put("IEOR", mock(Department.class));
+ expectedMapping.put("CHEM", mock(Department.class));
+ expectedMapping.put("PHYS", mock(Department.class));
+ expectedMapping.put("ELEN", mock(Department.class));
+ expectedMapping.put("PSYC", mock(Department.class));
+
+ verify(myFileDatabase).setMapping(
+ argThat(map -> map.keySet().containsAll(expectedMapping.keySet())));
+ }
+}
diff --git a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/MyFileDatabaseUnitTests.java b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/MyFileDatabaseUnitTests.java
new file mode 100644
index 00000000..7f0b0c58
--- /dev/null
+++ b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/MyFileDatabaseUnitTests.java
@@ -0,0 +1,105 @@
+package dev.coms4156.project.individualproject;
+
+import static org.assertj.core.api.Fail.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ContextConfiguration;
+
+
+/**
+ * This class contains the tests for the {@link MyFileDatabase} class.
+ * The tests verify the correctness of the MyFileDatabase class's methods.
+ */
+@SpringBootTest
+@ContextConfiguration
+public class MyFileDatabaseUnitTests {
+
+ /**
+ * Test instance of MyFileDatabase.
+ */
+ private MyFileDatabase myFileDatabase;
+
+ /**
+ * Initializes MyFileDatabase and cleans up before each test.
+ */
+ @BeforeEach
+ public void setupMyFileDatabaseForTesting() {
+ // Delete the file before each test if it exists
+ File file = new File("./testdata.txt");
+ if (file.exists()) {
+ file.delete();
+ }
+
+ // Initialize the MyFileDatabase instance
+ myFileDatabase = new MyFileDatabase(0, "./testdata.txt");
+ }
+
+ /**
+ * Tests the {@link MyFileDatabase#setMapping(HashMap)} method.
+ * Verifies that the mapping is correctly set and can be retrieved.
+ */
+ @Test
+ public void testSetMapping() {
+ Map testMapping = new HashMap<>();
+ Department compSciDepartment = new Department("COMS", new HashMap<>(), "John Doe", 300);
+ testMapping.put("COMS", compSciDepartment);
+
+ myFileDatabase.setMapping((HashMap) testMapping);
+
+ // Verify if the mapping is correctly set
+ assertEquals(compSciDepartment, myFileDatabase.getDepartmentMapping().get("COMS"));
+ }
+
+ /**
+ * Tests the {@link MyFileDatabase#saveContentsToFile()} method.
+ */
+ @Test
+ public void testSaveContentsToFile() {
+ Department department = new Department("COMS", new HashMap<>(), "John Doe", 300);
+ Map departmentMap = new HashMap<>();
+ departmentMap.put("COMS", department);
+ myFileDatabase.setMapping((HashMap) departmentMap);
+
+ // Call the method to save the contents to the file
+ myFileDatabase.saveContentsToFile();
+
+ File file = new File("./testdata.txt");
+
+ // Verify the contents of the file
+ try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
+ String line;
+ boolean contentFound = false;
+ while ((line = reader.readLine()) != null) {
+ if (line.contains("COMS")) {
+ contentFound = true; // Check that department data is saved
+ break;
+ }
+ }
+ assertTrue(contentFound);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Tests the {@link MyFileDatabase#deSerializeObjectFromFile()} method.
+ * Verifies that the file content is deserialized and loaded into the database.
+ */
+ @Test
+ public void testDeSerializeObjectFromFile() {
+ myFileDatabase.deSerializeObjectFromFile();
+
+ // Assuming file deserialization is working, additional verification can be added.
+ assertTrue(true); // Basic test to indicate the method was called.
+ }
+}
diff --git a/IndividualProject/src/test/java/dev/coms4156/project/individualproject/RouteControllerUnitTests.java b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/RouteControllerUnitTests.java
new file mode 100644
index 00000000..c83b0e41
--- /dev/null
+++ b/IndividualProject/src/test/java/dev/coms4156/project/individualproject/RouteControllerUnitTests.java
@@ -0,0 +1,340 @@
+package dev.coms4156.project.individualproject;
+
+import static org.mockito.Mockito.when;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+import java.util.HashMap;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockitoAnnotations;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+
+/**
+ * Contains unit tests for each endpoint in RouteController.
+ * */
+@WebMvcTest(RouteController.class)
+public class RouteControllerUnitTests {
+
+ @Autowired private MockMvc mockMvc;
+
+ @MockBean private MyFileDatabase mockDatabase;
+
+ private HashMap mockDepartments;
+ private HashMap mockCourses;
+
+ /**
+ * Set up the mock behavior of the static database in IndividualProjectApplication.
+ */
+ @BeforeEach
+ public void setUp() {
+ MockitoAnnotations.openMocks(this);
+
+ mockDepartments = new HashMap<>();
+ mockCourses = new HashMap<>();
+
+ Course mockCourse = new Course("Adam Cannon", "417 IAB", "11:40-12:55", 400);
+ mockCourse.setEnrolledStudentCount(5);
+ mockCourses.put("4156", mockCourse);
+ Department mockDepartment = new Department("COMS", mockCourses, "Luca Carloni", 2700);
+ mockDepartments.put("COMS", mockDepartment);
+
+ when(mockDatabase.getDepartmentMapping()).thenReturn(mockDepartments);
+
+ // Override static database
+ IndividualProjectApplication.overrideDatabase(mockDatabase);
+ }
+
+ @Test
+ public void testIndex() throws Exception {
+ mockMvc
+ .perform(MockMvcRequestBuilders.get("/"))
+ .andExpect(status().isOk())
+ .andExpect(
+ content()
+ .string("Welcome, in order to make an API call direct your browser "
+ + "or Postman to an endpoint \n"
+ + "\n This can be done using the following "
+ + "format: \n\n http:127.0.0.1:8080/endpoint?arg=value"));
+ }
+
+ @Test
+ public void testRetrieveDepartmentSuccess() throws Exception {
+ mockMvc
+ .perform(MockMvcRequestBuilders.get("/retrieveDept").param("deptCode", "COMS"))
+ .andExpect(status().isOk())
+ .andExpect(content().string(mockDepartments.get("COMS").toString()));
+ }
+
+ @Test
+ public void testRetrieveCourseSuccess() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.get("/retrieveCourse")
+ .param("deptCode", "COMS")
+ .param("courseCode", "4156"))
+ .andExpect(status().isOk())
+ .andExpect(content().string(mockCourses.get("4156").toString()));
+ }
+
+ @Test
+ public void testIsCourseFullSuccess() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.get("/isCourseFull")
+ .param("deptCode", "COMS")
+ .param("courseCode", "4156"))
+ .andExpect(status().isOk())
+ .andExpect(content().string(String.valueOf(mockCourses.get("4156").isCourseFull())));
+ }
+
+ @Test
+ public void testFindCourseLocationSuccess() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.get("/findCourseLocation")
+ .param("deptCode", "COMS")
+ .param("courseCode", "4156"))
+ .andExpect(status().isOk())
+ .andExpect(
+ content()
+ .string(
+ mockCourses.get("4156").getCourseLocation()
+ + " is where the course is located."));
+ }
+
+ @Test
+ public void testFindCourseInstructorSuccess() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.get("/findCourseInstructor")
+ .param("deptCode", "COMS")
+ .param("courseCode", "4156"))
+ .andExpect(status().isOk())
+ .andExpect(
+ content()
+ .string(
+ mockCourses.get("4156").getInstructorName()
+ + " is the instructor for the course."));
+ }
+
+ @Test
+ public void testFindCourseTimeSuccess() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.get("/findCourseTime")
+ .param("deptCode", "COMS")
+ .param("courseCode", "4156"))
+ .andExpect(status().isOk())
+ .andExpect(
+ content().string("The course meets at: "
+ + mockCourses.get("4156").getCourseTimeSlot()));
+ }
+
+ @Test
+ public void testIsCourseFullNotFound() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.get("/isCourseFull")
+ .param("deptCode", "COMS")
+ .param("courseCode", "0000"))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found"));
+ }
+
+ @Test
+ public void testGetMajorCtFromDeptSuccess() throws Exception {
+ mockMvc
+ .perform(MockMvcRequestBuilders.get("/getMajorCountFromDept").param("deptCode", "COMS"))
+ .andExpect(status().isOk())
+ .andExpect(
+ content()
+ .string(
+ "There are: "
+ + mockDepartments.get("COMS").getNumberOfMajors()
+ + " majors in the department"));
+ }
+
+ @Test
+ public void testIdentifyDeptChairSuccess() throws Exception {
+ mockMvc
+ .perform(MockMvcRequestBuilders.get("/idDeptChair").param("deptCode", "COMS"))
+ .andExpect(status().isOk())
+ .andExpect(
+ content()
+ .string(
+ mockDepartments.get("COMS").getDepartmentChair()
+ + " is the department chair."));
+ }
+
+ @Test
+ public void testAddMajorToDeptSuccess() throws Exception {
+ mockMvc
+ .perform(MockMvcRequestBuilders.patch("/addMajorToDept").param("deptCode", "COMS"))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Attribute was updated successfully"));
+ }
+
+ @Test
+ public void testRemoveMajorFromDeptSuccess() throws Exception {
+ mockMvc
+ .perform(MockMvcRequestBuilders.patch("/removeMajorFromDept").param("deptCode", "COMS"))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Attribute was updated or is at minimum"));
+ }
+
+ @Test
+ public void testDropStudentSuccess() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.patch("/dropStudentFromCourse")
+ .param("deptCode", "COMS")
+ .param("courseCode", "4156"))
+ .andExpect(status().isOk())
+ .andExpect(content().string("Student has been dropped."));
+ }
+
+ // Test for not found scenarios
+ @Test
+ public void testRetrieveDepartmentNotFound() throws Exception {
+ mockMvc
+ .perform(MockMvcRequestBuilders.get("/retrieveDept").param("deptCode", "ECON"))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Department Not Found"));
+ }
+
+ @Test
+ public void testRetrieveCourseDepartmentNotFound() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.get("/retrieveCourse")
+ .param("deptCode", "ECON")
+ .param("courseCode", "4156"))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Department Not Found"));
+ }
+
+ @Test
+ public void testRetrieveCourseNotFound() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.get("/retrieveCourse")
+ .param("deptCode", "COMS")
+ .param("courseCode", "0000"))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found"));
+ }
+
+ @Test
+ public void testFindCourseLocationNotFound() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.get("/findCourseLocation")
+ .param("deptCode", "COMS")
+ .param("courseCode", "0000"))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found"));
+ }
+
+ @Test
+ public void testFindCourseInstructorNotFound() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.get("/findCourseInstructor")
+ .param("deptCode", "COMS")
+ .param("courseCode", "0000"))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found"));
+ }
+
+ @Test
+ public void testFindCourseTimeNotFound() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.get("/findCourseTime")
+ .param("deptCode", "COMS")
+ .param("courseCode", "0000"))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found"));
+ }
+
+ @Test
+ public void testAddMajorToDeptNotFound() throws Exception {
+ mockMvc
+ .perform(MockMvcRequestBuilders.patch("/addMajorToDept").param("deptCode", "ECON"))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Department Not Found"));
+ }
+
+ @Test
+ public void testRemoveMajorFromDeptNotFound() throws Exception {
+ mockMvc
+ .perform(MockMvcRequestBuilders.patch(
+ "/removeMajorFromDept").param("deptCode", "ECON"))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Department Not Found"));
+ }
+
+ @Test
+ public void testDropStudentNotFound() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.patch("/dropStudentFromCourse")
+ .param("deptCode", "COMS")
+ .param("courseCode", "0000"))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found"));
+ }
+
+ @Test
+ public void testSetEnrollmentCountNotFound() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.patch("/setEnrollmentCount")
+ .param("deptCode", "COMS")
+ .param("courseCode", "0000")
+ .param("count", "20"))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found"));
+ }
+
+ @Test
+ public void testChangeCourseTimeNotFound() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.patch("/changeCourseTime")
+ .param("deptCode", "COMS")
+ .param("courseCode", "0000")
+ .param("time", "12:00-13:00"))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found"));
+ }
+
+ @Test
+ public void testChangeCourseTeacherNotFound() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.patch("/changeCourseTeacher")
+ .param("deptCode", "COMS")
+ .param("courseCode", "0000")
+ .param("teacher", "Gail Kaiser"))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found"));
+ }
+
+ @Test
+ public void testChangeCourseLocationNotFound() throws Exception {
+ mockMvc
+ .perform(
+ MockMvcRequestBuilders.patch("/changeCourseLocation")
+ .param("deptCode", "COMS")
+ .param("courseCode", "0000")
+ .param("location", "HAV 314"))
+ .andExpect(status().isNotFound())
+ .andExpect(content().string("Course Not Found"));
+ }
+}
diff --git a/bugs.txt b/bugs.txt
new file mode 100644
index 00000000..d1ae6ee6
--- /dev/null
+++ b/bugs.txt
@@ -0,0 +1,26 @@
+Courses.java:
+1. enrollStudent() added check if enrolledStudentCount >= enrollmentCapacity
+2. dropStudent() added check if enrolledStudentCount <= 0
+3. getCourseLocation() was originally get instructorName
+4. getInstructorName() was originally get courseLocation
+5. isCourseFull() should return true iff enrollmentCapacity <= enrolledStudentCount
+6. Course constructor should set this.enrolledStudentCount = 0 other than 500
+
+Department.java:
+1. getNumberOfMajors() was returning -this.numberOfMajors, should not be negative
+2. getDepartmentChair() was returning the literal "this.departmentChair", should be variable
+3. dropPersonFromMajor() added check if numberOfMajor > 0
+4. toString() was returning the literal "result.toString()", should be variable
+
+IndividualProjectApplication.java:
+No bugs found according to test cases
+
+MyFileDatabase.java:
+No bugs found according to test cases
+
+RouteController.java:
+1. ResponseEntity> retrieveDepartment() returns "...Not Found" when the dept is actually found, and returns departmentMapping.get(deptCode.toUpperCase()).toString() when the dept is actually not found
+2. ResponseEntity> retrieveCourse() returns HttpStatus.FORBIDDEN when the course is actually found, should return HttpStatus.OK
+3. public ResponseEntity> getMajorCtFromDept() returns -departmentMapping.get(deptCode) as it should not be negative, and it should return HttpStatus.NOT_FOUND instead of HttpStatus.FORBIDDEN when the department is not found
+4. ResponseEntity> findCourseTime() should return the actual time instead of the string literal "some time "
+5. ResponseEntity> handleException() should return HttpStatus.BAD_REQUEST instead of HttpStatus.OK
\ No newline at end of file
diff --git a/citations.txt b/citations.txt
new file mode 100644
index 00000000..1b4f3012
--- /dev/null
+++ b/citations.txt
@@ -0,0 +1,3 @@
+https://maven.apache.org/plugins/maven-checkstyle-plugin/
+https://www.baeldung.com/jacoco
+https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html
\ No newline at end of file
diff --git a/honesty.txt b/honesty.txt
new file mode 100644
index 00000000..7041a357
--- /dev/null
+++ b/honesty.txt
@@ -0,0 +1,14 @@
+I, Ken Deng, kd3005, have read and understood the following:
+
+CS department's Policies and Procedures on Academic Honesty
+The Course Specific Academic Honesty Policies
+The assignment specs outlining the consequences of not submitting this pledge and other aspects of the policy
+I affirm that I will abide by all the policies stated in the relevant materials from above. I understand that the relevant policies apply to: individual assignments, group projects, and individual examinations.
+
+I also affirm that I understand that all course materials, with the exception of the individual/group project, are subject to the appropriate copyrights and thus will not post them on any public forum or publicly hosted repository, this includes but is not limited to: GitHub, stackoverflow, chegg etc.
+
+I also affirm that I will be 100% honest when evaluating the performance of myself and my teammates when prompted by an assignment or member of the teaching staff.
+
+Finally I affirm that I will not attempt to find any loopholes in these policies for the benefit of myself or others enrolled in the course presently or possibly in the future.
+
+Signed: Ken Deng, kd3005, September 13th 2024
\ No newline at end of file