diff --git a/.idea/misc.xml b/.idea/misc.xml index 50fcc7b73769f6a832dae2b73894713d1ea8d808..a4e3fe0caaad2dfd6d241dba3025630a54131530 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,9 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> + <component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ProjectKey"> <option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" /> </component> - <component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="15" project-jdk-type="JavaSDK"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_14" default="true" project-jdk-name="14" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/out" /> </component> </project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 6c88efd7c77a713caeae3766463914815c091d78..0000000000000000000000000000000000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="ProjectModuleManager"> - <modules> - <module fileurl="file://$PROJECT_DIR$/tasc.iml" filepath="$PROJECT_DIR$/tasc.iml" /> - </modules> - </component> -</project> \ No newline at end of file diff --git a/build.gradle b/build.gradle index 030713498d8d2f1442cdc7bc4aa82609a592aa9b..bda7d133ba3d78bafb0981d39167d8f361c8fb49 100644 --- a/build.gradle +++ b/build.gradle @@ -22,6 +22,12 @@ dependencies { } +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(14)) + } +} + test { useJUnitPlatform() finalizedBy("jacocoTestReport") diff --git a/src/main/java/softeng/g4/Main.java b/src/main/java/softeng/g4/Main.java index f701378dea73d7764933f1eda50d5dc93ffcf3ee..9390a37a623452c1949da5f782d7d0b6ae5c5825 100644 --- a/src/main/java/softeng/g4/Main.java +++ b/src/main/java/softeng/g4/Main.java @@ -56,7 +56,7 @@ public class Main { CourseList courseList; UserList userList; - //--------Uncomment all of this for the "hardcoded" version. + // --------Uncomment all of this for the "hardcoded" version. // Uncomment to add a new fresh userList and courseList courseList = new CourseList(); userList = new UserList(); @@ -160,6 +160,57 @@ public class Main { // If we reach here, that means we found the user, and we are now logged in. AdminCLI.main(new String[]{searchUsername}); break; + + case "REGISTER": + System.out.println("(S)tudent / (T)eaching Assistant / (A)dmin?"); + String newUsername; + String newFullname; + Long newNPM; + switch (sc.nextLine()) { + case "S": + System.out.println("Enter your username:"); + newUsername = sc.nextLine(); + System.out.println("Enter your full name:"); + newFullname = sc.nextLine(); + System.out.println("Enter your NPM:"); + newNPM = Long.parseLong(sc.nextLine()); + new Student(newUsername, newFullname, newNPM, userList); + System.out.println("Successfully registered " + newUsername + " as a Student!"); + + // Save the new user + ListIO.saveList(courseList, userList); + break; + + case "T": + System.out.println("Enter your username:"); + newUsername = sc.nextLine(); + System.out.println("Enter your full name:"); + newFullname = sc.nextLine(); + System.out.println("Enter your NPM:"); + newNPM = Long.parseLong(sc.nextLine()); + new TeachingAssistant(newUsername, newFullname, newNPM, userList); + System.out.println("Successfully registered " + newUsername + " as a Teaching Assistant!"); + + // Save the new user + ListIO.saveList(courseList, userList); + break; + + case "A": + System.out.println("Enter your username:"); + newUsername = sc.nextLine(); + System.out.println("Enter your full name:"); + newFullname = sc.nextLine(); + new Admin(newUsername, newFullname, userList); + System.out.println("Successfully registered " + newUsername + " as an Admin!"); + + // Save the new user + ListIO.saveList(courseList, userList); + break; + + default: + System.out.println("Wrong input!"); + break; + } } } } @@ -168,6 +219,7 @@ public class Main { public static void intro() { System.out.println("Welcome to Teaching Assistant Student Connector (TASC) program by Group G4"); System.out.println("Type 'EXIT' to exit."); + System.out.println("Type REGISTER to register as a Student / Teaching Assistant / Admin."); System.out.println("Login as (S)tudent <username> / (T)eaching Assistant <username> / (A)dmin <username> ?"); System.out.println(); } diff --git a/src/main/java/softeng/g4/appointment/Appointment.java b/src/main/java/softeng/g4/appointment/Appointment.java index 4260d9c5e39237e1dbbbb8b28bca539602165b9a..6e6f1f8a42eaa9bc99a3221f54edff3cf7e20990 100644 --- a/src/main/java/softeng/g4/appointment/Appointment.java +++ b/src/main/java/softeng/g4/appointment/Appointment.java @@ -16,27 +16,15 @@ public class Appointment implements Serializable { private String description; private String status; - public Appointment(String date, Student student, TeachingAssistant ta, String startTime, String endTime, String decription, String status) { + public Appointment(String date, Student student, TeachingAssistant ta, String startTime, String endTime, String description) { this.id = generateId(); this.date = date; this.student = student; this.ta = ta; this.startTime = startTime; this.endTime = endTime; - this.description = decription; - this.status = status; - } - - public String getId (){ - return id; - } - - public void setStatus (String newstatus){ - this.status = newstatus; - } - - public Student getStudent() { - return student; + this.description = description; + this.status = "Pending"; } public String generateId(){ @@ -53,15 +41,26 @@ public class Appointment implements Serializable { String generatedString = buffer.toString(); return generatedString; } -// public Schedule(String startTime, String endTime) { -// this.name = "Free"; -// this.startTime = startTime; -// this.endTime = endTime; -// } public String toString() { return "ID: " + id + "\nDate: " + date + "\nStudent: " + student.getUsername() + "\nTA: " + ta.getUsername() + "\nStart Time : " + startTime + "\nEnd Time: " + endTime + "\nDescription: " + description + "\nStatus: " + status; //return date + student + " " + ta + " " + startTime + " - " + endTime + " " + description + status; } + public String getId (){ + return id; + } + + public Student getStudent() { + return student; + } + + public String getStatus() { + return status; + } + + public void setStatus (String newstatus){ + this.status = newstatus; + } + } diff --git a/src/main/java/softeng/g4/calendar/Calendar.java b/src/main/java/softeng/g4/calendar/Calendar.java index 93f97b682894642357d0f79a79f25085b52d9e30..88327826037536df494c179301b7e4d1980dc470 100644 --- a/src/main/java/softeng/g4/calendar/Calendar.java +++ b/src/main/java/softeng/g4/calendar/Calendar.java @@ -13,13 +13,7 @@ public class Calendar implements Serializable { private ArrayList<Schedule> friday = new ArrayList<Schedule>(); private ArrayList<Schedule> saturday = new ArrayList<Schedule>(); private ArrayList<Schedule> sunday = new ArrayList<Schedule>(); -// private ArrayList<Appointment> A_monday = new ArrayList<>(); -// private ArrayList<Appointment> A_tuesday = new ArrayList<>(); -// private ArrayList<Appointment> A_wednesday = new ArrayList<>(); -// private ArrayList<Appointment> A_thursday = new ArrayList<>(); -// private ArrayList<Appointment> A_friday = new ArrayList<>(); -// private ArrayList<Appointment> A_saturday = new ArrayList<>(); -// private ArrayList<Appointment> A_sunday = new ArrayList<>(); + private boolean adminPermission = false; public void showCalendar() { System.out.println("Monday:"); @@ -50,7 +44,7 @@ public class Calendar implements Serializable { for (Schedule schedule : sunday) { System.out.println(schedule.toString()); } - System.out.println(""); + System.out.println(); } // Add schedule to calendar @@ -84,9 +78,8 @@ public class Calendar implements Serializable { sunday.add(schedule); break; - // TODO: Need to change default case default: - monday.add(schedule); + System.out.println("Wrong day!"); break; } } @@ -119,41 +112,17 @@ public class Calendar implements Serializable { return sunday; } - // Add Appointment to calendar -// public void addAppointment(String day, Appointment appointment) { -// switch (day) { -// case "monday": -// A_monday.add(appointment); -// break; -// -// case "tuesday": -// A_tuesday.add(appointment); -// break; -// -// case "wednesday": -// A_wednesday.add(appointment); -// break; -// -// case "thursday": -// A_thursday.add(appointment); -// break; -// -// case "friday": -// A_friday.add(appointment); -// break; -// -// case "saturday": -// A_saturday.add(appointment); -// break; -// -// case "sunday": -// A_sunday.add(appointment); -// break; -// -// // TODO: Need to change default case -// default: -// A_monday.add(appointment); -// break; -// } -// } + public boolean isAdminPermission() { + return adminPermission; + } + + // Switches to allow / deny Admin to see Calendar + public void switchPermission() { + if (this.adminPermission) { + this.adminPermission = false; + } else { + this.adminPermission = true; + } + } + } diff --git a/src/main/java/softeng/g4/cli/AdminCLI.java b/src/main/java/softeng/g4/cli/AdminCLI.java index 2f10e2bec64a806f17c967cfd5857aa524e028b0..ef2acd400a87cd59b8f1c6b28c0fe65ae62aa79d 100644 --- a/src/main/java/softeng/g4/cli/AdminCLI.java +++ b/src/main/java/softeng/g4/cli/AdminCLI.java @@ -46,7 +46,7 @@ public class AdminCLI extends CLI { System.out.println("Choose SKS: "); int sks = Integer.valueOf(sc.nextLine()); new Course(name, courseId, professor, sks, courseList); - System.out.println("Sucessfully added a new course!"); + System.out.println("Successfully added a new course!"); break; case "COURSE DETAILS": @@ -60,13 +60,30 @@ public class AdminCLI extends CLI { break; case "ASSIGN TA": - System.out.println("Input TA's username: "); - String qTA = sc.nextLine(); System.out.println("Input courseId: "); String qCourse = sc.nextLine(); + System.out.println("Input TA's username: "); + String qTA = sc.nextLine(); currentAdmin.setCourseTA(userList.searchTA(qTA), courseList.searchCourse(qCourse)); break; + case "SET COORDINATOR": + System.out.println("Input courseId:"); + Course theCourse = courseList.searchCourse(sc.nextLine()); + System.out.println("Input TA's username you want to set as the coordinator role:"); + theCourse.setCoordinatorRole(sc.nextLine()); + break; + + case "CALENDAR": + System.out.println("Enter TA's Username: "); + currentAdmin.seeCalendar(sc.nextLine(), userList); + break; + + case "ASK PERMISSION": + System.out.println("Input TA's username:"); + currentAdmin.askPermission(sc.nextLine(), userList); + break; + case "LOG OUT": break; @@ -87,6 +104,9 @@ public class AdminCLI extends CLI { System.out.println("ADD COURSE \t\t\t Add new course."); System.out.println("COURSE DETAILS \t\t See course details with the right courseId."); System.out.println("ASSIGN TA \t\t\t Assign TA to a course."); + System.out.println("SET COORDINATOR \t Assign a current TA responsible for a course as a coordinator role."); + System.out.println("CALENDAR \t\t\t See a TA's calendar."); + System.out.println("ASK PERMISSION \t\t Ask a TA to see their calendar."); System.out.println(); } diff --git a/src/main/java/softeng/g4/cli/StudentCLI.java b/src/main/java/softeng/g4/cli/StudentCLI.java index bd71989af599c2147259e13cf18be0fa4b39d9f5..40a9b5eec74d9fe2689768292c6f9794b205dcb1 100644 --- a/src/main/java/softeng/g4/cli/StudentCLI.java +++ b/src/main/java/softeng/g4/cli/StudentCLI.java @@ -39,20 +39,18 @@ public class StudentCLI extends CLI { String endTime = sc.nextLine(); System.out.println("(Optional) Add description for your appointment: "); String description = sc.nextLine(); - String status = "Pending"; - currentStudent.setAppointment(day, ta, startTime, endTime, description, status, userList); + currentStudent.setAppointment(day, ta, startTime, endTime, description, userList); System.out.println("Successfully added a new appointment!"); break; case "APPOINTMENTS": - for (Appointment appointment : currentStudent.appointmentlist) { + for (Appointment appointment : currentStudent.appointmentList) { System.out.println(appointment); System.out.println(); } break; case "CALENDAR": - // TODO: Make this such that users can see TA's calendar by inputting their username System.out.println("Enter TA's Username: "); currentStudent.seeCalendar(sc.nextLine(), userList); break; diff --git a/src/main/java/softeng/g4/cli/TACLI.java b/src/main/java/softeng/g4/cli/TACLI.java index 051a33bdff3cd72c1b64df191d5cb658fa797806..911ab583264d515889eea1b37c565b4f205595f4 100644 --- a/src/main/java/softeng/g4/cli/TACLI.java +++ b/src/main/java/softeng/g4/cli/TACLI.java @@ -18,6 +18,9 @@ public class TACLI extends CLI { intro(currentTA); + // Prints notification for an admin asking permission to see calendar, if there's one. + currentTA.getAskPermissionAdmin(); + while (!q.equals("LOG OUT")) { // Saves the list everytime the user is in the "Main menu" ListIO.saveList(courseList, userList); @@ -50,7 +53,7 @@ public class TACLI extends CLI { System.out.println("Sucessfully added a new schedule!"); case "APPOINTMENTS": - for (Appointment appointment : currentTA.appointmentlist) { + for (Appointment appointment : currentTA.appointmentList) { System.out.println(appointment); System.out.println(); } @@ -66,6 +69,15 @@ public class TACLI extends CLI { currentTA.rejectAppointment(sc.nextLine(), userList); break; + case "SET PERMISSION": + currentTA.switchPermission(); + if (currentTA.getCalendar().isAdminPermission()) { + System.out.println("Your calendar is now viewable to all Admins!"); + } else { + System.out.println("Your calendar is now private."); + } + break; + case "LOG OUT": break; @@ -86,8 +98,9 @@ public class TACLI extends CLI { System.out.println("COURSELIST \t\t\t See all courses."); System.out.println("ADD SCHEDULE \t\t Add new schedule."); System.out.println("APPOINTMENTS \t\t See all your appointments."); - System.out.println("ACCEPT APPOINTMENT \t\t Appointment you want to accept."); - System.out.println("REJECT APPOINTMENT \t\t Appointment you want to reject."); + System.out.println("ACCEPT APPOINTMENT \t Appointment you want to accept."); + System.out.println("REJECT APPOINTMENT \t Appointment you want to reject."); + System.out.println("SET PERMISSION \t\t Allow / deny Admins to see your schedule."); System.out.println(); } diff --git a/src/main/java/softeng/g4/course/Course.java b/src/main/java/softeng/g4/course/Course.java index 870358c2b74c2bf87af33dd5be9faeba58204c8c..0278661029f858b38db1bcc4e0406eb7e9ad1557 100644 --- a/src/main/java/softeng/g4/course/Course.java +++ b/src/main/java/softeng/g4/course/Course.java @@ -13,6 +13,7 @@ public class Course implements Serializable { private ArrayList<TeachingAssistant> teachingAssistants = new ArrayList<TeachingAssistant>(); private String professor; private int sks; + private int coordinatorRoleIndex; private boolean adminPermission; // Constructor @@ -37,10 +38,30 @@ public class Course implements Serializable { System.out.println("Professor: " + professor); System.out.println("SKS: " + sks); System.out.println("Responsible TA(s):"); - for (TeachingAssistant ta : teachingAssistants) System.out.println(ta); + for (int i = 0; i < teachingAssistants.size(); i++) { + TeachingAssistant currentTA = teachingAssistants.get(i); + if (i == coordinatorRoleIndex) { + System.out.println(currentTA + " (Coordinator)"); + } else { + System.out.println(currentTA); + } + } System.out.println(); } + public void setCoordinatorRole(String username) { + boolean found = false; + for (int i = 0; i < teachingAssistants.size(); i++) { + if (teachingAssistants.get(i).getUsername().equals(username)) { + this.coordinatorRoleIndex = i; + found = true; + System.out.println("Successfully set Teaching Assistant " + username + " role as a coordinator."); + break; + } + } + if (found == false) System.out.println("Wrong username!"); + } + public String getCourseId() { return courseId; } diff --git a/src/main/java/softeng/g4/courselist.txt b/src/main/java/softeng/g4/courselist.txt index 2555c67c185d67ae014f1c4de6f348a648717ded..78205cca124823c59a88f3c86c6743e200e92c72 100644 Binary files a/src/main/java/softeng/g4/courselist.txt and b/src/main/java/softeng/g4/courselist.txt differ diff --git a/src/main/java/softeng/g4/user/Admin.java b/src/main/java/softeng/g4/user/Admin.java index f79b89b84e43183a1b9c79ea697b6d83c12f5683..efaebe70a29de706023e933a61da9fedaa97975d 100644 --- a/src/main/java/softeng/g4/user/Admin.java +++ b/src/main/java/softeng/g4/user/Admin.java @@ -18,9 +18,6 @@ public class Admin extends User { userList.userList.add(this); } - // TODO: Change the role of the teaching assistant to something else? (needs to be discussed) - public void assignRole(TeachingAssistant ta) {} - // Assign TA to the course public void setCourseTA(TeachingAssistant ta, Course course) { if (ta.getUsername().equals("falseTA") || course.getCourseId().equals("FALSECOURSE")) { @@ -32,11 +29,6 @@ public class Admin extends User { System.out.println(); } - // Create course - public void createCourse(String name, String courseId, String professor, int sks, CourseList courseList) { - new Course(name, courseId, professor, sks, courseList); - } - // See all courses public void seeCourseList(CourseList courseList) { courseList.showCourseList(); @@ -57,10 +49,24 @@ public class Admin extends User { } // TODO: Iteration 3 - Admin can see the appointment, if appointment has the permission true - public void seeAppointment(Appointment ap) {} + public void seeAppointment(Appointment ap) { + } + + public void askPermission(String username, UserList userList) { + TeachingAssistant searchedTA = userList.searchTA(username); + searchedTA.setAskPermissionAdmin(this); + System.out.println("You have successfully asked " + searchedTA.getUsername() + " to see their calendar!"); + } // TODO: Iteration 3 - Admin can see the TA's calendar, if calendar has the permission true - public void seeCalendar(TeachingAssistant ta) {} + public void seeCalendar(String username, UserList userList) { + TeachingAssistant searchedTA = userList.searchTA(username); + if (searchedTA.getCalendar().isAdminPermission()) { + searchedTA.getCalendar().showCalendar(); + } else { + System.out.println("You don't have permission to see " + username + "'s calendar!"); + } + } public String toString() { return username + " - " + fullname; diff --git a/src/main/java/softeng/g4/user/Student.java b/src/main/java/softeng/g4/user/Student.java index a2c88d45634dc71ca7819ca0aebef85438df652a..13bdf621fd7af0a11ac12121d7cd8fba056419cf 100644 --- a/src/main/java/softeng/g4/user/Student.java +++ b/src/main/java/softeng/g4/user/Student.java @@ -11,7 +11,7 @@ public class Student extends UserStudent { private String fullname; private String role; private long npm; - public ArrayList<Appointment> appointmentlist = new ArrayList<Appointment>(); + public ArrayList<Appointment> appointmentList = new ArrayList<Appointment>(); // Constructor @@ -26,25 +26,17 @@ public class Student extends UserStudent { } // TODO: Adds appointment with the corresponding TeachingAssistant - public void setAppointment(String date, String TAusername, String startTime, String endTime, String description, String status, UserList userList) { + public void setAppointment(String date, String TAusername, String startTime, String endTime, String description, UserList userList) { TeachingAssistant ta = userList.searchTA(TAusername); if(ta.getUsername().equals("falseTA")){ System.out.println("TA not found"); - } else{ - Appointment newAppointment = new Appointment(date, this, ta, startTime, endTime, description, status); + } else { + Appointment newAppointment = new Appointment(date, this, ta, startTime, endTime, description); //this.calendar.addAppointment(day, newAppointment); - this.appointmentlist.add(newAppointment); - ta.appointmentlist.add(newAppointment); + this.appointmentList.add(newAppointment); + ta.appointmentList.add(newAppointment); } } - public void addAppointment() { - } - - // Not a necessary method to implement. Just a bonus if there's enough time. - public void addReminder() {} - - // TODO: After adding appointment, the student will have an option to add a description or not. - public void addDescription() {} // See this Student's calendar // temporary calendar diff --git a/src/main/java/softeng/g4/user/TeachingAssistant.java b/src/main/java/softeng/g4/user/TeachingAssistant.java index 5d1d9fdd3e7aad437aed5c91e4f541428a5d878e..f65a63c2f2b0220ccc9f48cb084fbbc8b90b0ecf 100644 --- a/src/main/java/softeng/g4/user/TeachingAssistant.java +++ b/src/main/java/softeng/g4/user/TeachingAssistant.java @@ -12,8 +12,9 @@ public class TeachingAssistant extends UserStudent { private String fullname; private String role; private long npm; + private Admin askPermissionAdmin = null; private Calendar calendar = new Calendar(); - public ArrayList<Appointment> appointmentlist = new ArrayList<Appointment>(); + public ArrayList<Appointment> appointmentList = new ArrayList<Appointment>(); // Constructor public TeachingAssistant(String username, String fullname, long npm, UserList userList) { @@ -37,11 +38,6 @@ public class TeachingAssistant extends UserStudent { this.calendar.addSchedule(day, newSchedule); } -// public void setAppointment(String day, String name, String ta, String startTime, String endTime, String description, String status) { -// Appointment newAppointment = new Appointment(name, ta, startTime, endTime, description, status); -// this.calendar.addAppointment(day, newAppointment); -// } - // See this TA's calendar public void seeCalendar() { this.calendar.showCalendar(); @@ -50,47 +46,65 @@ public class TeachingAssistant extends UserStudent { // TODO: Implement these 2 methods such that they can change the status of the appointment to accepted or rejected public void acceptAppointment(String id, UserList userList) { boolean found = false; - for(Appointment appointment : appointmentlist){ - if (appointment.getId().equals(id)){ + for (Appointment appointment : appointmentList) { + if (appointment.getId().equals(id)) { found = true; appointment.setStatus("Accepted"); Student student = userList.searchStudent(appointment.getStudent().getUsername()); - for(Appointment studentappointment: student.appointmentlist){ - if (studentappointment.getId().equals(id)){ + for (Appointment studentappointment : student.appointmentList) { + if (studentappointment.getId().equals(id)) { studentappointment.setStatus("Accepted"); } } } } - if(found == false){ + if (found == false) { System.out.println("Appointment not found"); - }else{ + } else { System.out.println("Appointment with ID " + id + " has been accepted"); } } + public void rejectAppointment(String id, UserList userList) { boolean found = false; - for(Appointment appointment : appointmentlist){ - if (appointment.getId().equals(id)){ + for (Appointment appointment : appointmentList) { + if (appointment.getId().equals(id)) { found = true; appointment.setStatus("Rejected"); Student student = userList.searchStudent(appointment.getStudent().getUsername()); - for(Appointment studentappointment: student.appointmentlist){ - if (studentappointment.getId().equals(id)){ + for (Appointment studentappointment : student.appointmentList) { + if (studentappointment.getId().equals(id)) { studentappointment.setStatus("Rejected"); } } } } - if(found == false){ + if (found == false) { System.out.println("Appointment not found."); - }else{ + } else { System.out.println("Appointment with ID " + id + " has been rejected."); } } - // Not a necessary method to implement. Just a bonus if there's enough time. - public void addReminder() {} + // Everytime this method is invoked, askPermissionAdmin will be updated to null + public void getAskPermissionAdmin() { + if (this.askPermissionAdmin != null) { + System.out.println(); + System.out.println("ALERT!"); + System.out.println( + "Admin " + this.askPermissionAdmin.getUsername() + " wants permission to see your calendar!"); + System.out.println(); + this.askPermissionAdmin = null; + } + } + + public void setAskPermissionAdmin(Admin askPermissionAdmin) { + this.askPermissionAdmin = askPermissionAdmin; + } + + public void switchPermission() { + this.calendar.switchPermission(); + } public String toString() { return username + " - " + fullname; diff --git a/src/main/java/softeng/g4/userlist.txt b/src/main/java/softeng/g4/userlist.txt index e6b5bf4015b5d3f1cb392337b3c02d7c2376dd4c..1ca37198c9f8b256499889ba3f24302a421291d9 100644 Binary files a/src/main/java/softeng/g4/userlist.txt and b/src/main/java/softeng/g4/userlist.txt differ diff --git a/src/softeng/g4/Main.java b/src/softeng/g4/Main.java deleted file mode 100644 index 9e0f1a99701a72bd2e38efe25b2814756ffa8ebd..0000000000000000000000000000000000000000 --- a/src/softeng/g4/Main.java +++ /dev/null @@ -1,444 +0,0 @@ -package softeng.g4; - -import jdk.swing.interop.SwingInterOpUtils; -import softeng.g4.appointment.Appointment; -import softeng.g4.course.Course; -import softeng.g4.course.CourseList; -import softeng.g4.user.*; - -import java.io.*; -import java.util.*; - -public class Main { - - /** - * TODOS for something general - * TODO: Needs refactoring and exception handling!!!! (especially the latter one) - * TODO: Create a class / method(s) for handling storage. Maybe something like ListIO? - * TODO: Create classes for different user types (TACLI, STUDENTCLI, ADMINCLI), and use them in the Main class - * It should be possible to make login of each user types to different classes, - * rather than using switch cases like a madman. - */ - - /** - * TODOs for "LOG IN" FEATURE - * IT's DONE. You can login by using their username. - * Ex: S akuStudent - * Ex: T akuTA - * Ex: A akuAdmin - * - * If you want to register a new user, - * you'll have to run a constructor of Student / TeachingAssistant / Admin - * Ex: New Student("exampleUsername", "Example Fullname", Long.valueOf("exampleNPM"), userList); - */ - - /** - * TODOs for "APPOINTMENT" FEATURE - * TODO: Implement the methods and attributes in the Appointment.java - * TODO: Implement the methods and attributes in the RequestAppointment.java - * TODO: Edit Main.java's intro methods, switch cases, Student.java, TeachingAssistant.java, Admin.java, - * Appointment.java, RequestAppointment.java, and maybe more, such that: - * - Student can add appointments - * - TeachingAssistant can accept / reject appointment by changing the appointment status - * - Both Student and TeachingAssistant can see the appointment details - * - Admin can ask permission to see the appointment details, which then they're able to see the appointment - * TODO: After all this TODOs are done, change Main.java such that it doesn't use the hardcoded version again - */ - - public static void main(String[] args) { - Scanner sc = new Scanner(System.in); - String q = ""; - String currentLogin = ""; - CourseList courseList; - UserList userList; - -// // -------- Uncomment all of this for the "hardcoded" version. -// // Uncomment to add a new fresh userList and courseList -// courseList = new CourseList(); -// userList = new UserList(); -// -// // Uncomment here to add a new TA or Admin -// // This will add false users, for checking users in the arraylist. (NECESSARY) -// new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); -// new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); -// new Admin("falseAdmin", "False Admin", userList); -// -// // Add testStudent -// new Student("akuStudent", "Aku Student", Long.valueOf("123456789"), userList); -// -// // Add testTa with a mock calendar and schedule -// TeachingAssistant testTa = new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"), userList); -// testTa.setSchedule("monday", "Free", "12:00", "17:00"); -// testTa.setSchedule("tuesday", "Free", "08:00", "11:00"); -// testTa.setSchedule("tuesday", "Free", "12:00", "15:00"); -// testTa.setSchedule("saturday", "Busy", "07:00", "21:00"); -// testTa.setSchedule("sunday", "Free", "12:00", "17:00"); -// new TeachingAssistant("anotherTA", "Another TA", Long.valueOf("1"), userList); -// -// // Add testAdmin -// new Admin("akuAdmin", "Aku Admin", userList); -// -// // Add false course -// new Course("False Course", "FALSECOURSE", "False Professor", 0, courseList); -// -// // Add mock courses -// new Course("Mata Kuliah", "MATKUL420", "Aku Dosen", 4, courseList); -// new Course("Software Engineering", "SOFTENG2021", "Aku Professor", 3, courseList); -// new Course("Fisika", "PHYS101", "Aku Dosen Fisika", 4, courseList); -// -// // Save the course -// saveList(courseList, userList); -// -// // ---------------- END OF "HARDCODED" VERSION - - // PRODUCTION BUILD: Open all persistent storage - courseList = openCourseList(); - userList = openUserList(); - -// // Store userList test -// try { -// FileOutputStream fos = new FileOutputStream("src/softeng/g4/userlist.txt"); -// ObjectOutputStream oos = new ObjectOutputStream(fos); -// oos.writeObject(userList); -// -// } catch (Exception ex) { -// System.out.println("Exception is caught"); -// } - - - while (true) { - - intro(); - q = sc.nextLine(); - - // EXITS THE PROGRAM AND SERIALIZE ALL LIST, IF USER COMMAND IS "EXIT" - if (q.equals("EXIT")) { - System.out.println("Thank you for using our program! Have a good day!"); - saveList(courseList, userList); - break; - } - - // TODO: Maybe it is better to move this whole if block into a different class - String[] splited = {" ", " "}; - splited = q.split("\\s+"); // Split by space - String searchUsername; - - // Exception handling if user does not provide a correct username - try { - searchUsername = splited[1]; - } catch (Exception ex) { - searchUsername = "false"; - } - - String role = splited[0]; - - currentLogin = role; - - if (currentLogin.equals("S")) { - // Find student in userList. If not exist, immediately log out - Student currentStudent = userList.searchStudent(searchUsername); - if (currentStudent.getUsername().equals("falseStudent")) { - q = "LOG OUT"; - System.out.println("Wrong username!"); - } else introStudent(currentStudent); // If we reach here, that means we found the user, and we are now logged in. - - while (!q.equals("LOG OUT")) { - saveList(courseList, userList); // Saves the list everytime the user is in the "Main menu" - System.out.print("Input: "); - q = sc.nextLine(); - switch (q) { - case "HELP": - introStudent(currentStudent); - break; - - case "ADD APPOINTMENT": - System.out.println("Choose date 'dd/mm' . Example, '31/12': "); - String day = sc.nextLine().toLowerCase(); - System.out.println("Your TA's username: "); - String ta = sc.nextLine(); - System.out.println("Add start time 'XX:XX'. Example, '08:00': "); - String startTime = sc.nextLine(); - System.out.println("Add end time 'XX:XX'. Example, '09:40': "); - String endTime = sc.nextLine(); - System.out.println("(Optional) Add description for your appointment: "); - String description = sc.nextLine(); - String status = "Pending"; - currentStudent.setAppointment(day, ta, startTime, endTime, description, status, userList); - System.out.println("Successfully added a new appointment!"); - break; - - case "APPOINTMENTS": - for(Appointment appointment : currentStudent.appointmentlist){ - System.out.println(appointment); - System.out.println(); - } - break; - - case "CALENDAR": - // TODO: Make this such that users can see TA's calendar by inputting their username - System.out.println("Enter TA's Username: "); - currentStudent.seeCalendar(sc.nextLine(), userList); - break; - - case "LOG OUT": - break; - - default: - System.out.println("Wrong input. Type HELP to see available commands"); - break; - } - } - - } else if (currentLogin.equals("T")) { - // Find teaching assistant in userList. If not exist, immediately log out - TeachingAssistant currentTA = userList.searchTA(searchUsername); - if (currentTA.getUsername().equals("falseTA")) { - q = "LOG OUT"; - System.out.println("Wrong username!"); - } else introTA(currentTA); // If we reach here, that means we found the user, and we are now logged in. - - while (!q.equals("LOG OUT")) { - saveList(courseList, userList); // Saves the list everytime the user is in the "Main menu" - System.out.print("Input: "); - q = sc.nextLine(); - switch (q) { - case "HELP": - introTA(currentTA); - break; - - case "CALENDAR": - currentTA.seeCalendar(); - break; - - case "COURSELIST": - currentTA.seeCourseList(courseList); - break; - - case "ADD SCHEDULE": - //TODO: Move this to a different function - System.out.println("Choose day (Monday, Tuesday, etc.): "); - String day = sc.nextLine().toLowerCase(); - System.out.println("Schedule name: "); - String name = sc.nextLine(); - System.out.println("Add start time 'XX:XX'. Example, '08:00': "); - String startTime = sc.nextLine(); - System.out.println("Add end time 'XX:XX'. Example, '09:40': "); - String endTime = sc.nextLine(); - currentTA.setSchedule(day, name, startTime, endTime); - System.out.println("Sucessfully added a new schedule!"); - - case "APPOINTMENTS": - for(Appointment appointment : currentTA.appointmentlist){ - System.out.println(appointment); - System.out.println(); - } - break; - - case "ACCEPT APPOINTMENT": - System.out.println("Enter the Appointment ID: "); - currentTA.acceptAppointment(sc.nextLine(), userList); - break; - - case "REJECT APPOINTMENT": - System.out.println("Enter the Appointment ID: "); - currentTA.rejectAppointment(sc.nextLine(), userList); - break; - - case "LOG OUT": - break; - - default: - System.out.println("Wrong input. Type HELP to see available commands"); - break; - } - } - } else if (currentLogin.equals("A")) { - // Find Admin in userList. If not exist, immediately log out - Admin currentAdmin = userList.searchAdmin(searchUsername); - if (currentAdmin.getUsername().equals("falseAdmin")) { - q = "LOG OUT"; - System.out.println("Wrong username!"); - } else introAdmin(currentAdmin); // If we reach here, that means we found the user, and we are now logged in. - - while (!q.equals("LOG OUT")) { - saveList(courseList, userList); // Saves the list everytime the user is in the "Main menu" - System.out.print("Input: "); - q = sc.nextLine(); - switch (q) { - case "HELP": - introAdmin(currentAdmin); - break; - - case "COURSELIST": - currentAdmin.seeCourseList(courseList); - break; - - case "USERLIST": - currentAdmin.getUserList(userList); - break; - - case "ADD COURSE": - System.out.println("Course name: "); - String name = sc.nextLine(); - System.out.println("Course Id: "); - String courseId = sc.nextLine(); - System.out.println("Professor name: "); - String professor = sc.nextLine(); - System.out.println("Choose SKS: "); - int sks = Integer.valueOf(sc.nextLine()); - new Course(name, courseId, professor, sks, courseList); - System.out.println("Sucessfully added a new course!"); - break; - - case "COURSE DETAILS": - System.out.println("Input courseId:"); - Course searchedCourse = courseList.searchCourse(sc.nextLine()); - if (searchedCourse.getCourseId().equals("FALSECOURSE")) { - System.out.println("Wrong courseId. \n"); - } else { - searchedCourse.getCourseDetail(); - } - break; - - case "ASSIGN TA": - System.out.println("Input TA's username: "); - String qTA = sc.nextLine(); - System.out.println("Input courseId: "); - String qCourse = sc.nextLine(); - currentAdmin.setCourseTA(userList.searchTA(qTA), courseList.searchCourse(qCourse)); - break; - - case "LOG OUT": - break; - - default: - System.out.println("Wrong input. Type HELP to see available commands"); - break; - } - } - } - - - } - } - - - public static void intro() { - System.out.println("Welcome to Teaching Assistant Student Connector (TASC) program by Group G4"); - System.out.println("Type 'EXIT' to exit."); - System.out.println("Login as (S)tudent <username> / (T)eaching Assistant <username> / (A)dmin <username> ?"); - System.out.println(); - } - -// public static Student checkLoginStudent(String q, String role, UserList userList) { -// -// } - - public static void introStudent(Student currentStudent) { - System.out.println("You are logged in as a student (" + currentStudent.getUsername() + ")"); - System.out.println("Type 'LOG OUT' to log out."); - System.out.println("Available commands:"); - System.out.println("HELP \t\t\t\t Show available commands."); - System.out.println("CALENDAR \t\t\t See a TA's calendar."); - System.out.println("ADD APPOINTMENT \t Schedule an appointment with TA"); - System.out.println("APPOINTMENTS \t\t See all your appointments"); - System.out.println(); - } - - public static void introTA(TeachingAssistant currentTA) { - System.out.println("You are logged in as a teaching assistant (" + currentTA.getUsername() + ")"); - System.out.println("Type 'LOG OUT' to log out."); - System.out.println("Available commands:"); - System.out.println("HELP \t\t\t\t Show available commands."); - System.out.println("CALENDAR \t\t\t See your calendar."); - System.out.println("COURSELIST \t\t\t See all courses."); - System.out.println("ADD SCHEDULE \t\t Add new schedule."); - System.out.println("APPOINTMENTS \t\t See all your appointments."); - System.out.println("ACCEPT APPOINTMENT \t\t Appointment you want to accept."); - System.out.println("REJECT APPOINTMENT \t\t Appointment you want to reject."); - System.out.println(); - } - - public static void introAdmin(Admin currentAdmin) { - System.out.println("You are logged in as an admin (" + currentAdmin.getUsername() + ")"); - System.out.println("Type 'LOG OUT' to log out."); - System.out.println("Available commands:"); - System.out.println("HELP \t\t\t\t Show available commands."); - System.out.println("COURSELIST \t\t\t See all courses."); - System.out.println("USERLIST \t\t\t See all users' username."); - System.out.println("ADD COURSE \t\t\t Add new course."); - System.out.println("COURSE DETAILS \t\t See course details with the right courseId."); - System.out.println("ASSIGN TA \t\t\t Assign TA to a course."); - System.out.println(); - } - - // Open courselist.txt for persistent storage of list of courses - public static CourseList openCourseList() { - try { - // Reading the object from a file - FileInputStream file = new FileInputStream("src/softeng/g4/courselist.txt"); - ObjectInputStream in = new ObjectInputStream(file); - - // Method for deserialization of object - CourseList courseList = (CourseList) in.readObject(); - - in.close(); - file.close(); - - return courseList; - } catch (IOException ex) { - System.out.println("IOException is caught"); - } catch (ClassNotFoundException ex) { - System.out.println("ClassNotFoundException is caught"); - } - - return null; - } - - // Open userlist.txt for persistent storage of list of users - public static UserList openUserList() { - try { - // Reading the object from a file - FileInputStream file = new FileInputStream("src/softeng/g4/userlist.txt"); - ObjectInputStream in = new ObjectInputStream(file); - - // Method for deserialization of object - UserList userList = (UserList) in.readObject(); - - in.close(); - file.close(); - - return userList; - } catch (IOException ex) { - System.out.println("IOException is caught"); - } catch (ClassNotFoundException ex) { - System.out.println("ClassNotFoundException is caught"); - } - - return null; - } - - // Store all list - public static void saveList(CourseList courseList, UserList userList) { - // Store courseList - try { - FileOutputStream fos = new FileOutputStream("src/softeng/g4/courselist.txt"); - ObjectOutputStream oos = new ObjectOutputStream(fos); - oos.writeObject(courseList); - - } catch (Exception ex) { - System.out.println("Exception is caught"); - } - - // Store userList - try { - FileOutputStream fos = new FileOutputStream("src/softeng/g4/userlist.txt"); - ObjectOutputStream oos = new ObjectOutputStream(fos); - oos.writeObject(userList); - - } catch (Exception ex) { - System.out.println("Exception is caught"); - } - } - -} diff --git a/src/softeng/g4/appointment/Appointment.java b/src/softeng/g4/appointment/Appointment.java deleted file mode 100644 index 4260d9c5e39237e1dbbbb8b28bca539602165b9a..0000000000000000000000000000000000000000 --- a/src/softeng/g4/appointment/Appointment.java +++ /dev/null @@ -1,67 +0,0 @@ -package softeng.g4.appointment; - -import softeng.g4.user.Student; -import softeng.g4.user.TeachingAssistant; - -import java.io.Serializable; -import java.util.Random; - -public class Appointment implements Serializable { - private String id; - private String date; - private TeachingAssistant ta; - private Student student; - private String startTime; - private String endTime; - private String description; - private String status; - - public Appointment(String date, Student student, TeachingAssistant ta, String startTime, String endTime, String decription, String status) { - this.id = generateId(); - this.date = date; - this.student = student; - this.ta = ta; - this.startTime = startTime; - this.endTime = endTime; - this.description = decription; - this.status = status; - } - - public String getId (){ - return id; - } - - public void setStatus (String newstatus){ - this.status = newstatus; - } - - public Student getStudent() { - return student; - } - - public String generateId(){ - int leftLimit = 65; // letter 'A' - int rightLimit = 90; // letter 'Z' - int targetStringLength = 5; - Random random = new Random(); - StringBuilder buffer = new StringBuilder(targetStringLength); - for (int i = 0; i < targetStringLength; i++) { - int randomLimitedInt = leftLimit + (int) - (random.nextFloat() * (rightLimit - leftLimit + 1)); - buffer.append((char) randomLimitedInt); - } - String generatedString = buffer.toString(); - return generatedString; - } -// public Schedule(String startTime, String endTime) { -// this.name = "Free"; -// this.startTime = startTime; -// this.endTime = endTime; -// } - - public String toString() { - return "ID: " + id + "\nDate: " + date + "\nStudent: " + student.getUsername() + "\nTA: " + ta.getUsername() + "\nStart Time : " + startTime + "\nEnd Time: " + endTime + "\nDescription: " + description + "\nStatus: " + status; - //return date + student + " " + ta + " " + startTime + " - " + endTime + " " + description + status; - } - -} diff --git a/src/softeng/g4/appointment/Reminder.java b/src/softeng/g4/appointment/Reminder.java deleted file mode 100644 index 7a8174ef82e3b1e247915aca04d8c3ecebe395b4..0000000000000000000000000000000000000000 --- a/src/softeng/g4/appointment/Reminder.java +++ /dev/null @@ -1,4 +0,0 @@ -package softeng.g4.appointment; - -public class Reminder { -} diff --git a/src/softeng/g4/appointment/RequestAppointment.java b/src/softeng/g4/appointment/RequestAppointment.java deleted file mode 100644 index 9a655b647c373001ea1ecb6c93bcedd38138e72b..0000000000000000000000000000000000000000 --- a/src/softeng/g4/appointment/RequestAppointment.java +++ /dev/null @@ -1,4 +0,0 @@ -package softeng.g4.appointment; - -public class RequestAppointment { -} diff --git a/src/softeng/g4/calendar/Calendar.java b/src/softeng/g4/calendar/Calendar.java deleted file mode 100644 index 884219108cb3f04157e752a223a82b0a0f989bd7..0000000000000000000000000000000000000000 --- a/src/softeng/g4/calendar/Calendar.java +++ /dev/null @@ -1,130 +0,0 @@ -package softeng.g4.calendar; - -import softeng.g4.appointment.Appointment; - -import java.io.Serializable; -import java.util.ArrayList; - -public class Calendar implements Serializable { - private ArrayList<Schedule> monday = new ArrayList<Schedule>(); - private ArrayList<Schedule> tuesday = new ArrayList<Schedule>(); - private ArrayList<Schedule> wednesday = new ArrayList<Schedule>(); - private ArrayList<Schedule> thursday = new ArrayList<Schedule>(); - private ArrayList<Schedule> friday = new ArrayList<Schedule>(); - private ArrayList<Schedule> saturday = new ArrayList<Schedule>(); - private ArrayList<Schedule> sunday = new ArrayList<Schedule>(); -// private ArrayList<Appointment> A_monday = new ArrayList<>(); -// private ArrayList<Appointment> A_tuesday = new ArrayList<>(); -// private ArrayList<Appointment> A_wednesday = new ArrayList<>(); -// private ArrayList<Appointment> A_thursday = new ArrayList<>(); -// private ArrayList<Appointment> A_friday = new ArrayList<>(); -// private ArrayList<Appointment> A_saturday = new ArrayList<>(); -// private ArrayList<Appointment> A_sunday = new ArrayList<>(); - - public void showCalendar() { - System.out.println("Monday:"); - for (Schedule schedule : monday) { - System.out.println(schedule.toString()); - } - System.out.println("Tuesday:"); - for (Schedule schedule : tuesday) { - System.out.println(schedule.toString()); - } - System.out.println("Wednesday:"); - for (Schedule schedule : wednesday) { - System.out.println(schedule.toString()); - } - System.out.println("Thursday:"); - for (Schedule schedule : thursday) { - System.out.println(schedule.toString()); - } - System.out.println("Friday:"); - for (Schedule schedule : friday) { - System.out.println(schedule.toString()); - } - System.out.println("Saturday:"); - for (Schedule schedule : saturday) { - System.out.println(schedule.toString()); - } - System.out.println("Sunday:"); - for (Schedule schedule : sunday) { - System.out.println(schedule.toString()); - } - System.out.println(""); - } - - // Add schedule to calendar - public void addSchedule(String day, Schedule schedule) { - switch (day) { - case "monday": - monday.add(schedule); - break; - - case "tuesday": - tuesday.add(schedule); - break; - - case "wednesday": - wednesday.add(schedule); - break; - - case "thursday": - thursday.add(schedule); - break; - - case "friday": - friday.add(schedule); - break; - - case "saturday": - saturday.add(schedule); - break; - - case "sunday": - sunday.add(schedule); - break; - - // TODO: Need to change default case - default: - monday.add(schedule); - break; - } - } - // Add Appointment to calendar -// public void addAppointment(String day, Appointment appointment) { -// switch (day) { -// case "monday": -// A_monday.add(appointment); -// break; -// -// case "tuesday": -// A_tuesday.add(appointment); -// break; -// -// case "wednesday": -// A_wednesday.add(appointment); -// break; -// -// case "thursday": -// A_thursday.add(appointment); -// break; -// -// case "friday": -// A_friday.add(appointment); -// break; -// -// case "saturday": -// A_saturday.add(appointment); -// break; -// -// case "sunday": -// A_sunday.add(appointment); -// break; -// -// // TODO: Need to change default case -// default: -// A_monday.add(appointment); -// break; -// } -// } -} diff --git a/src/softeng/g4/calendar/Schedule.java b/src/softeng/g4/calendar/Schedule.java deleted file mode 100644 index 3113701ca54ec4b8a7ebfde6ad756049f3e8bbd9..0000000000000000000000000000000000000000 --- a/src/softeng/g4/calendar/Schedule.java +++ /dev/null @@ -1,25 +0,0 @@ -package softeng.g4.calendar; - -import java.io.Serializable; - -public class Schedule implements Serializable { - private String name; - private String startTime; - private String endTime; - - public Schedule(String name, String startTime, String endTime) { - this.name = name; - this.startTime = startTime; - this.endTime = endTime; - } - - public Schedule(String startTime, String endTime) { - this.name = "Free"; - this.startTime = startTime; - this.endTime = endTime; - } - - public String toString() { - return name + " " + startTime + " - " + endTime; - } -} diff --git a/src/softeng/g4/cli/TACLI.java b/src/softeng/g4/cli/TACLI.java deleted file mode 100644 index e554eaba282240e520efa42e6c1448376b4148fd..0000000000000000000000000000000000000000 --- a/src/softeng/g4/cli/TACLI.java +++ /dev/null @@ -1,4 +0,0 @@ -package softeng.g4.cli; - -public class TACLI { -} diff --git a/src/softeng/g4/course/Course.java b/src/softeng/g4/course/Course.java deleted file mode 100644 index 870358c2b74c2bf87af33dd5be9faeba58204c8c..0000000000000000000000000000000000000000 --- a/src/softeng/g4/course/Course.java +++ /dev/null @@ -1,52 +0,0 @@ -package softeng.g4.course; - -import softeng.g4.user.Student; -import softeng.g4.user.TeachingAssistant; - -import java.io.Serializable; -import java.util.ArrayList; - -public class Course implements Serializable { - private String name; - private String courseId; - private ArrayList<Student> students = new ArrayList<Student>(); - private ArrayList<TeachingAssistant> teachingAssistants = new ArrayList<TeachingAssistant>(); - private String professor; - private int sks; - private boolean adminPermission; - - // Constructor - public Course(String name, String courseId, String professor, int sks, CourseList courseList) { - this.name = name; - this.courseId = courseId; - this.professor = professor; - this.sks = sks; - this.adminPermission = false; - - courseList.courseList.add(this); - } - - // Assign TA to the course - public void setTA(TeachingAssistant ta) { - this.teachingAssistants.add(ta); - } - - // Prints course details - public void getCourseDetail() { - System.out.println(name + " - " + courseId); - System.out.println("Professor: " + professor); - System.out.println("SKS: " + sks); - System.out.println("Responsible TA(s):"); - for (TeachingAssistant ta : teachingAssistants) System.out.println(ta); - System.out.println(); - } - - public String getCourseId() { - return courseId; - } - - // toString() method to print the course in an orderly manner - public String toString() { - return name + " - " + courseId + " | Professor: " + professor + " | SKS: " + sks; - } -} diff --git a/src/softeng/g4/course/CourseList.java b/src/softeng/g4/course/CourseList.java deleted file mode 100644 index d23a15a34e9f5b9e08fcf5071ffcc0d76bf71c7b..0000000000000000000000000000000000000000 --- a/src/softeng/g4/course/CourseList.java +++ /dev/null @@ -1,31 +0,0 @@ -package softeng.g4.course; - -import softeng.g4.user.Student; -import softeng.g4.user.User; - -import java.io.Serializable; -import java.util.ArrayList; - -public class CourseList implements Serializable { - public ArrayList<Course> courseList = new ArrayList<Course>(); - - // Shows the course list in an orderly manner - public void showCourseList() { - for (int i = 1; i < courseList.size(); i++) { - System.out.println(courseList.get(i)); - } - System.out.println(); - } - - // Returns the corresponding course, if found. - public Course searchCourse(String courseId) { - for (Course course : courseList) { - // Linear search courses by their courseId - if (course.getCourseId().equals(courseId)) { - return course; - } - } - // Returns a course called False Course, so user will have to search the course with the correct course name - return courseList.get(0); - } -} diff --git a/src/softeng/g4/courselist.txt b/src/softeng/g4/courselist.txt deleted file mode 100644 index 2555c67c185d67ae014f1c4de6f348a648717ded..0000000000000000000000000000000000000000 Binary files a/src/softeng/g4/courselist.txt and /dev/null differ diff --git a/src/softeng/g4/user/Admin.java b/src/softeng/g4/user/Admin.java deleted file mode 100644 index f79b89b84e43183a1b9c79ea697b6d83c12f5683..0000000000000000000000000000000000000000 --- a/src/softeng/g4/user/Admin.java +++ /dev/null @@ -1,76 +0,0 @@ -package softeng.g4.user; - -import softeng.g4.appointment.Appointment; -import softeng.g4.course.Course; -import softeng.g4.course.CourseList; - -public class Admin extends User { - private String username; - private String fullname; - private String role; - - public Admin(String username, String fullname, UserList userList) { - this.username = username; - this.fullname = fullname; - this.role = "A"; - - // Register new Admin to the userList - userList.userList.add(this); - } - - // TODO: Change the role of the teaching assistant to something else? (needs to be discussed) - public void assignRole(TeachingAssistant ta) {} - - // Assign TA to the course - public void setCourseTA(TeachingAssistant ta, Course course) { - if (ta.getUsername().equals("falseTA") || course.getCourseId().equals("FALSECOURSE")) { - System.out.println("Wrong TA or CourseId. Try again."); - } else { - System.out.println("Teaching Assistant " + ta.getUsername() + " has successfully assigned to course " + course.getCourseId()); - course.setTA(ta); - } - System.out.println(); - } - - // Create course - public void createCourse(String name, String courseId, String professor, int sks, CourseList courseList) { - new Course(name, courseId, professor, sks, courseList); - } - - // See all courses - public void seeCourseList(CourseList courseList) { - courseList.showCourseList(); - } - - // Shows all the users except for the false users - public void getUserList(UserList userList) { - for (int i = 3; i < userList.userList.size(); i++) { - System.out.println(userList.userList.get(i)); - } - - System.out.println(); - - // Uncomment to include the printing of the false users -// for (User user: userList.userList) { -// System.out.println(user); -// } - } - - // TODO: Iteration 3 - Admin can see the appointment, if appointment has the permission true - public void seeAppointment(Appointment ap) {} - - // TODO: Iteration 3 - Admin can see the TA's calendar, if calendar has the permission true - public void seeCalendar(TeachingAssistant ta) {} - - public String toString() { - return username + " - " + fullname; - } - - public String getRole() { - return role; - } - - public String getUsername() { - return username; - } -} diff --git a/src/softeng/g4/user/Student.java b/src/softeng/g4/user/Student.java deleted file mode 100644 index a2c88d45634dc71ca7819ca0aebef85438df652a..0000000000000000000000000000000000000000 --- a/src/softeng/g4/user/Student.java +++ /dev/null @@ -1,70 +0,0 @@ -package softeng.g4.user; - -import softeng.g4.calendar.Calendar; -import softeng.g4.calendar.Schedule; -import softeng.g4.appointment.Appointment; - -import java.util.ArrayList; - -public class Student extends UserStudent { - private String username; - private String fullname; - private String role; - private long npm; - public ArrayList<Appointment> appointmentlist = new ArrayList<Appointment>(); - - - // Constructor - public Student(String username, String fullname, long npm, UserList userList) { - this.username = username; - this.fullname = fullname; - this.role = "S"; - this.npm = npm; - - // Register new TA to the userList - userList.userList.add(this); - } - - // TODO: Adds appointment with the corresponding TeachingAssistant - public void setAppointment(String date, String TAusername, String startTime, String endTime, String description, String status, UserList userList) { - TeachingAssistant ta = userList.searchTA(TAusername); - if(ta.getUsername().equals("falseTA")){ - System.out.println("TA not found"); - } else{ - Appointment newAppointment = new Appointment(date, this, ta, startTime, endTime, description, status); - //this.calendar.addAppointment(day, newAppointment); - this.appointmentlist.add(newAppointment); - ta.appointmentlist.add(newAppointment); - } - } - public void addAppointment() { - } - - // Not a necessary method to implement. Just a bonus if there's enough time. - public void addReminder() {} - - // TODO: After adding appointment, the student will have an option to add a description or not. - public void addDescription() {} - - // See this Student's calendar - // temporary calendar - // TODO: Change this method such that it returns the TA's calendar by searching for their username - public void seeCalendar(String TAusername, UserList userList) { - TeachingAssistant ta = userList.searchTA(TAusername); - ta.seeCalendar(); - } - - - public String getRole() { - return role; - } - - public String getUsername() { - return username; - } - - public String toString() { - return username + " - " + fullname; - } - -} diff --git a/src/softeng/g4/user/TeachingAssistant.java b/src/softeng/g4/user/TeachingAssistant.java deleted file mode 100644 index 06c4b432024d920d667fabbdd58b1e355276e5cc..0000000000000000000000000000000000000000 --- a/src/softeng/g4/user/TeachingAssistant.java +++ /dev/null @@ -1,106 +0,0 @@ -package softeng.g4.user; - -import softeng.g4.appointment.Appointment; -import softeng.g4.course.CourseList; -import softeng.g4.calendar.Calendar; -import softeng.g4.calendar.Schedule; - -import java.util.ArrayList; - -public class TeachingAssistant extends UserStudent { - private String username; - private String fullname; - private String role; - private long npm; - private Calendar calendar = new Calendar(); - public ArrayList<Appointment> appointmentlist = new ArrayList<Appointment>(); - - // Constructor - public TeachingAssistant(String username, String fullname, long npm, UserList userList) { - this.username = username; - this.fullname = fullname; - this.role = "TA"; - this.npm = npm; - - // Register new TA to the userList - userList.userList.add(this); - } - - // See all courses - public void seeCourseList(CourseList courseList) { - courseList.showCourseList(); - } - - // Set schedule on certain day - public void setSchedule(String day, String name, String startTime, String endTime) { - Schedule newSchedule = new Schedule(name, startTime, endTime); - this.calendar.addSchedule(day, newSchedule); - } - -// public void setAppointment(String day, String name, String ta, String startTime, String endTime, String description, String status) { -// Appointment newAppointment = new Appointment(name, ta, startTime, endTime, description, status); -// this.calendar.addAppointment(day, newAppointment); -// } - - // See this TA's calendar - public void seeCalendar() { - this.calendar.showCalendar(); - } - - // TODO: Implement these 2 methods such that they can change the status of the appointment to accepted or rejected - public void acceptAppointment(String id, UserList userList) { - boolean found = false; - for(Appointment appointment : appointmentlist){ - if (appointment.getId().equals(id)){ - found = true; - appointment.setStatus("Accepted"); - Student student = userList.searchStudent(appointment.getStudent().getUsername()); - for(Appointment studentappointment: student.appointmentlist){ - if (studentappointment.getId().equals(id)){ - studentappointment.setStatus("Accepted"); - } - } - } - } - if(found == false){ - System.out.println("Appointment not found"); - }else{ - System.out.println("Appointment with ID " + id + " has been accepted"); - } - } - public void rejectAppointment(String id, UserList userList) { - boolean found = false; - for(Appointment appointment : appointmentlist){ - if (appointment.getId().equals(id)){ - found = true; - appointment.setStatus("Rejected"); - Student student = userList.searchStudent(appointment.getStudent().getUsername()); - for(Appointment studentappointment: student.appointmentlist){ - if (studentappointment.getId().equals(id)){ - studentappointment.setStatus("Rejected"); - } - } - } - } - if(found == false){ - System.out.println("Appointment not found."); - }else{ - System.out.println("Appointment with ID " + id + " has been rejected."); - } - } - - // Not a necessary method to implement. Just a bonus if there's enough time. - public void addReminder() {} - - public String toString() { - return username + " - " + fullname; - } - - public String getRole() { - return role; - } - - public String getUsername() { - return username; - } -} diff --git a/src/softeng/g4/user/User.java b/src/softeng/g4/user/User.java deleted file mode 100644 index 982ab9202ff9c7b7d96caf3bd575dcc14eae977c..0000000000000000000000000000000000000000 --- a/src/softeng/g4/user/User.java +++ /dev/null @@ -1,16 +0,0 @@ -package softeng.g4.user; - -import java.io.Serializable; - -public abstract class User implements Serializable { - private String username; - private String role; - - public String getRole() { - return role; - } - - public String getUsername() { - return username; - } -} diff --git a/src/softeng/g4/user/UserList.java b/src/softeng/g4/user/UserList.java deleted file mode 100644 index 9b0f187303d7877edd8d57b438a1fef85791d2aa..0000000000000000000000000000000000000000 --- a/src/softeng/g4/user/UserList.java +++ /dev/null @@ -1,45 +0,0 @@ -package softeng.g4.user; - -import softeng.g4.course.Course; - -import java.io.Serializable; -import java.util.ArrayList; - -public class UserList implements Serializable { - public ArrayList<User> userList = new ArrayList<User>(); - - // Returns student - public Student searchStudent(String username) { - for (User user : userList) { - try { - Student currentUser = (Student) user; - if (currentUser.getUsername().equals(username) && currentUser.getRole().equals("S")) return currentUser; - } catch (Exception ex) { } - } - // Return a student called falseStudent, so user will have to re-login with the correct username - return (Student) userList.get(0); - } - - public TeachingAssistant searchTA(String username) { - for (User user : userList) { - try { - TeachingAssistant currentUser = (TeachingAssistant) user; - if (currentUser.getUsername().equals(username) && currentUser.getRole().equals("TA")) return currentUser; - } catch (Exception ex) { } - } - // Return a student called falseStudent, so user will have to re-login with the correct username - return (TeachingAssistant) userList.get(1); - } - - public Admin searchAdmin(String username) { - for (User user : userList) { - try { - Admin currentUser = (Admin) user; - if (currentUser.getUsername().equals(username) && currentUser.getRole().equals("A")) return currentUser; - } catch (Exception ex) { } - } - // Return a student called falseStudent, so user will have to re-login with the correct username - return (Admin) userList.get(2); - } - -} diff --git a/src/softeng/g4/user/UserStudent.java b/src/softeng/g4/user/UserStudent.java deleted file mode 100644 index 7a9c504d10c30686d90b9e5f399b25b21722094d..0000000000000000000000000000000000000000 --- a/src/softeng/g4/user/UserStudent.java +++ /dev/null @@ -1,6 +0,0 @@ -package softeng.g4.user; - -public abstract class UserStudent extends User{ - private long npm; - -} diff --git a/src/softeng/g4/userlist.txt b/src/softeng/g4/userlist.txt deleted file mode 100644 index b4c0fb66d59cb4565421c01427998f099c8f1dcb..0000000000000000000000000000000000000000 Binary files a/src/softeng/g4/userlist.txt and /dev/null differ diff --git a/src/test/java/softeng/g4/MainTest.java b/src/test/java/softeng/g4/MainTest.java new file mode 100644 index 0000000000000000000000000000000000000000..dff24a907b03cc7451b8de9ecb3b9134bb5db49a --- /dev/null +++ b/src/test/java/softeng/g4/MainTest.java @@ -0,0 +1,86 @@ +package softeng.g4; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import softeng.g4.cli.ListIO; +import softeng.g4.course.Course; +import softeng.g4.course.CourseList; +import softeng.g4.user.Admin; +import softeng.g4.user.Student; +import softeng.g4.user.TeachingAssistant; +import softeng.g4.user.UserList; + +import static org.junit.jupiter.api.Assertions.*; + +class MainTest { + + private UserList userList; + private CourseList courseList; + private Admin testAdmin; + private TeachingAssistant testTa; + private Student testStudent; + + @BeforeEach + void setUpTearDown() { + userList = new UserList(); + courseList = new CourseList(); + + // This will add false users, for checking users in the arraylist. (NECESSARY) + new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); + new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); + new Admin("falseAdmin", "False Admin", userList); + + testAdmin = new Admin("testAdmin", "Test Admin", userList); + testTa = new TeachingAssistant("testTa", + "Test Teacher", Long.parseLong("123456789"), userList); + testStudent = new Student("testStudent", + "Test Student", Long.valueOf("123456789"), userList); + } + + @Test + void main() { + } + + @Test + void intro() { + } + + @AfterEach + void finalTearDown() { + courseList = new CourseList(); + userList = new UserList(); + + // Uncomment here to add a new TA or Admin + // This will add false users, for checking users in the arraylist. (NECESSARY) + new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); + new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); + new Admin("falseAdmin", "False Admin", userList); + + // Add testStudent + new Student("akuStudent", "Aku Student", Long.valueOf("123456789"), userList); + + // Add testTa with a mock calendar and schedule + TeachingAssistant testTa = new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"), userList); + testTa.setSchedule("monday", "Free", "12:00", "17:00"); + testTa.setSchedule("tuesday", "Free", "08:00", "11:00"); + testTa.setSchedule("tuesday", "Free", "12:00", "15:00"); + testTa.setSchedule("saturday", "Busy", "07:00", "21:00"); + testTa.setSchedule("sunday", "Free", "12:00", "17:00"); + new TeachingAssistant("anotherTA", "Another TA", Long.valueOf("1"), userList); + + // Add testAdmin + new Admin("akuAdmin", "Aku Admin", userList); + + // Add false course + new Course("False Course", "FALSECOURSE", "False Professor", 0, courseList); + + // Add mock courses + new Course("Mata Kuliah", "MATKUL420", "Aku Dosen", 4, courseList); + new Course("Software Engineering", "SOFTENG2021", "Aku Professor", 3, courseList); + new Course("Fisika", "PHYS101", "Aku Dosen Fisika", 4, courseList); + + // Save the course + ListIO.saveList(courseList, userList); + } +} \ No newline at end of file diff --git a/src/test/java/softeng/g4/cli/AdminCLITest.java b/src/test/java/softeng/g4/cli/AdminCLITest.java new file mode 100644 index 0000000000000000000000000000000000000000..02ae651ab966a3888b446ff47d5efa34ef106d17 --- /dev/null +++ b/src/test/java/softeng/g4/cli/AdminCLITest.java @@ -0,0 +1,86 @@ +package softeng.g4.cli; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import softeng.g4.course.Course; +import softeng.g4.course.CourseList; +import softeng.g4.user.Admin; +import softeng.g4.user.Student; +import softeng.g4.user.TeachingAssistant; +import softeng.g4.user.UserList; + +import static org.junit.jupiter.api.Assertions.*; + +class AdminCLITest { + + private UserList userList; + private CourseList courseList; + private Admin testAdmin; + private TeachingAssistant testTa; + private Student testStudent; + + @BeforeEach + void setUpTearDown() { + userList = new UserList(); + courseList = new CourseList(); + + // This will add false users, for checking users in the arraylist. (NECESSARY) + new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); + new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); + new Admin("falseAdmin", "False Admin", userList); + + testAdmin = new Admin("testAdmin", "Test Admin", userList); + testTa = new TeachingAssistant("testTa", + "Test Teacher", Long.parseLong("123456789"), userList); + testStudent = new Student("testStudent", + "Test Student", Long.valueOf("123456789"), userList); + } + + @Test + void main() { + } + + @Test + void intro() { + } + + @AfterEach + void finalTearDown() { + courseList = new CourseList(); + userList = new UserList(); + + // Uncomment here to add a new TA or Admin + // This will add false users, for checking users in the arraylist. (NECESSARY) + new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); + new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); + new Admin("falseAdmin", "False Admin", userList); + + // Add testStudent + new Student("akuStudent", "Aku Student", Long.valueOf("123456789"), userList); + + // Add testTa with a mock calendar and schedule + TeachingAssistant testTa = new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"), userList); + testTa.setSchedule("monday", "Free", "12:00", "17:00"); + testTa.setSchedule("tuesday", "Free", "08:00", "11:00"); + testTa.setSchedule("tuesday", "Free", "12:00", "15:00"); + testTa.setSchedule("saturday", "Busy", "07:00", "21:00"); + testTa.setSchedule("sunday", "Free", "12:00", "17:00"); + new TeachingAssistant("anotherTA", "Another TA", Long.valueOf("1"), userList); + + // Add testAdmin + new Admin("akuAdmin", "Aku Admin", userList); + + // Add false course + new Course("False Course", "FALSECOURSE", "False Professor", 0, courseList); + + // Add mock courses + new Course("Mata Kuliah", "MATKUL420", "Aku Dosen", 4, courseList); + new Course("Software Engineering", "SOFTENG2021", "Aku Professor", 3, courseList); + new Course("Fisika", "PHYS101", "Aku Dosen Fisika", 4, courseList); + + // Save the course + ListIO.saveList(courseList, userList); + } +} \ No newline at end of file diff --git a/src/test/java/softeng/g4/cli/ListIOTest.java b/src/test/java/softeng/g4/cli/ListIOTest.java new file mode 100644 index 0000000000000000000000000000000000000000..9839c1d855a8ec9f13a87cffc5a13b4300bba23e --- /dev/null +++ b/src/test/java/softeng/g4/cli/ListIOTest.java @@ -0,0 +1,105 @@ +package softeng.g4.cli; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import softeng.g4.course.Course; +import softeng.g4.course.CourseList; +import softeng.g4.user.Admin; +import softeng.g4.user.Student; +import softeng.g4.user.TeachingAssistant; +import softeng.g4.user.UserList; + +import static org.junit.jupiter.api.Assertions.*; + +class ListIOTest { + + private UserList userList; + private CourseList courseList; + private Admin testAdmin; + private TeachingAssistant testTa; + private Student testStudent; + + @BeforeEach + void setUpTearDown() { + userList = new UserList(); + courseList = new CourseList(); + + // This will add false users, for checking users in the arraylist. (NECESSARY) + new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); + new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); + new Admin("falseAdmin", "False Admin", userList); + + testAdmin = new Admin("testAdmin", "Test Admin", userList); + testTa = new TeachingAssistant("testTa", + "Test Teacher", Long.parseLong("123456789"), userList); + testStudent = new Student("testStudent", + "Test Student", Long.valueOf("123456789"), userList); + } + + @Test + void openCourseList() { + courseList = ListIO.openCourseList(); + assertEquals(courseList, courseList); + } + + @Test + void openUserList() { + userList = ListIO.openUserList(); + assertEquals(userList, userList); + } + + @Test + void saveList() { + new Admin("newTestAdmin", "New Test Admin", userList); + new TeachingAssistant("newTestTa", + "New Test Teacher", Long.parseLong("123456789"), userList); + new Student("newTestStudent", + "New Test Student", Long.valueOf("123456789"), userList); + new Course("test", "TEST", "Test Professor", 1, courseList); + + ListIO.saveList(courseList, userList); + + assertEquals(userList, userList); + assertEquals(courseList, courseList); + } + + @AfterEach + void finalTearDown() { + courseList = new CourseList(); + userList = new UserList(); + + // Uncomment here to add a new TA or Admin + // This will add false users, for checking users in the arraylist. (NECESSARY) + new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); + new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); + new Admin("falseAdmin", "False Admin", userList); + + // Add testStudent + new Student("akuStudent", "Aku Student", Long.valueOf("123456789"), userList); + + // Add testTa with a mock calendar and schedule + TeachingAssistant testTa = new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"), userList); + testTa.setSchedule("monday", "Free", "12:00", "17:00"); + testTa.setSchedule("tuesday", "Free", "08:00", "11:00"); + testTa.setSchedule("tuesday", "Free", "12:00", "15:00"); + testTa.setSchedule("saturday", "Busy", "07:00", "21:00"); + testTa.setSchedule("sunday", "Free", "12:00", "17:00"); + new TeachingAssistant("anotherTA", "Another TA", Long.valueOf("1"), userList); + + // Add testAdmin + new Admin("akuAdmin", "Aku Admin", userList); + + // Add false course + new Course("False Course", "FALSECOURSE", "False Professor", 0, courseList); + + // Add mock courses + new Course("Mata Kuliah", "MATKUL420", "Aku Dosen", 4, courseList); + new Course("Software Engineering", "SOFTENG2021", "Aku Professor", 3, courseList); + new Course("Fisika", "PHYS101", "Aku Dosen Fisika", 4, courseList); + + // Save the course + ListIO.saveList(courseList, userList); + } +} \ No newline at end of file diff --git a/src/test/java/softeng/g4/cli/StudentCLITest.java b/src/test/java/softeng/g4/cli/StudentCLITest.java new file mode 100644 index 0000000000000000000000000000000000000000..f8abb92f2e041eefe78a8284a4521387b4a60f28 --- /dev/null +++ b/src/test/java/softeng/g4/cli/StudentCLITest.java @@ -0,0 +1,86 @@ +package softeng.g4.cli; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import softeng.g4.course.Course; +import softeng.g4.course.CourseList; +import softeng.g4.user.Admin; +import softeng.g4.user.Student; +import softeng.g4.user.TeachingAssistant; +import softeng.g4.user.UserList; + +import static org.junit.jupiter.api.Assertions.*; + +class StudentCLITest { + + private UserList userList; + private CourseList courseList; + private Admin testAdmin; + private TeachingAssistant testTa; + private Student testStudent; + + @BeforeEach + void setUpTearDown() { + userList = new UserList(); + courseList = new CourseList(); + + // This will add false users, for checking users in the arraylist. (NECESSARY) + new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); + new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); + new Admin("falseAdmin", "False Admin", userList); + + testAdmin = new Admin("testAdmin", "Test Admin", userList); + testTa = new TeachingAssistant("testTa", + "Test Teacher", Long.parseLong("123456789"), userList); + testStudent = new Student("testStudent", + "Test Student", Long.valueOf("123456789"), userList); + } + + @Test + void main() { + } + + @Test + void intro() { + } + + @AfterEach + void finalTearDown() { + courseList = new CourseList(); + userList = new UserList(); + + // Uncomment here to add a new TA or Admin + // This will add false users, for checking users in the arraylist. (NECESSARY) + new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); + new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); + new Admin("falseAdmin", "False Admin", userList); + + // Add testStudent + new Student("akuStudent", "Aku Student", Long.valueOf("123456789"), userList); + + // Add testTa with a mock calendar and schedule + TeachingAssistant testTa = new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"), userList); + testTa.setSchedule("monday", "Free", "12:00", "17:00"); + testTa.setSchedule("tuesday", "Free", "08:00", "11:00"); + testTa.setSchedule("tuesday", "Free", "12:00", "15:00"); + testTa.setSchedule("saturday", "Busy", "07:00", "21:00"); + testTa.setSchedule("sunday", "Free", "12:00", "17:00"); + new TeachingAssistant("anotherTA", "Another TA", Long.valueOf("1"), userList); + + // Add testAdmin + new Admin("akuAdmin", "Aku Admin", userList); + + // Add false course + new Course("False Course", "FALSECOURSE", "False Professor", 0, courseList); + + // Add mock courses + new Course("Mata Kuliah", "MATKUL420", "Aku Dosen", 4, courseList); + new Course("Software Engineering", "SOFTENG2021", "Aku Professor", 3, courseList); + new Course("Fisika", "PHYS101", "Aku Dosen Fisika", 4, courseList); + + // Save the course + ListIO.saveList(courseList, userList); + } +} \ No newline at end of file diff --git a/src/test/java/softeng/g4/cli/TACLITest.java b/src/test/java/softeng/g4/cli/TACLITest.java new file mode 100644 index 0000000000000000000000000000000000000000..efa29eb33130d97d4462495b9c6512f40fc5f0cf --- /dev/null +++ b/src/test/java/softeng/g4/cli/TACLITest.java @@ -0,0 +1,86 @@ +package softeng.g4.cli; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import softeng.g4.course.Course; +import softeng.g4.course.CourseList; +import softeng.g4.user.Admin; +import softeng.g4.user.Student; +import softeng.g4.user.TeachingAssistant; +import softeng.g4.user.UserList; + +import static org.junit.jupiter.api.Assertions.*; + +class TACLITest { + + private UserList userList; + private CourseList courseList; + private Admin testAdmin; + private TeachingAssistant testTa; + private Student testStudent; + + @BeforeEach + void setUpTearDown() { + userList = new UserList(); + courseList = new CourseList(); + + // This will add false users, for checking users in the arraylist. (NECESSARY) + new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); + new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); + new Admin("falseAdmin", "False Admin", userList); + + testAdmin = new Admin("testAdmin", "Test Admin", userList); + testTa = new TeachingAssistant("testTa", + "Test Teacher", Long.parseLong("123456789"), userList); + testStudent = new Student("testStudent", + "Test Student", Long.valueOf("123456789"), userList); + } + + @Test + void main() { + } + + @Test + void intro() { + } + + @AfterEach + void finalTearDown() { + courseList = new CourseList(); + userList = new UserList(); + + // Uncomment here to add a new TA or Admin + // This will add false users, for checking users in the arraylist. (NECESSARY) + new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); + new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); + new Admin("falseAdmin", "False Admin", userList); + + // Add testStudent + new Student("akuStudent", "Aku Student", Long.valueOf("123456789"), userList); + + // Add testTa with a mock calendar and schedule + TeachingAssistant testTa = new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"), userList); + testTa.setSchedule("monday", "Free", "12:00", "17:00"); + testTa.setSchedule("tuesday", "Free", "08:00", "11:00"); + testTa.setSchedule("tuesday", "Free", "12:00", "15:00"); + testTa.setSchedule("saturday", "Busy", "07:00", "21:00"); + testTa.setSchedule("sunday", "Free", "12:00", "17:00"); + new TeachingAssistant("anotherTA", "Another TA", Long.valueOf("1"), userList); + + // Add testAdmin + new Admin("akuAdmin", "Aku Admin", userList); + + // Add false course + new Course("False Course", "FALSECOURSE", "False Professor", 0, courseList); + + // Add mock courses + new Course("Mata Kuliah", "MATKUL420", "Aku Dosen", 4, courseList); + new Course("Software Engineering", "SOFTENG2021", "Aku Professor", 3, courseList); + new Course("Fisika", "PHYS101", "Aku Dosen Fisika", 4, courseList); + + // Save the course + ListIO.saveList(courseList, userList); + } +} \ No newline at end of file diff --git a/src/test/java/softeng/g4/user/AdminTest.java b/src/test/java/softeng/g4/user/AdminTest.java new file mode 100644 index 0000000000000000000000000000000000000000..9c9504482f21271c897acf7cd78938ea6001fb03 --- /dev/null +++ b/src/test/java/softeng/g4/user/AdminTest.java @@ -0,0 +1,115 @@ +package softeng.g4.user; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import softeng.g4.cli.ListIO; +import softeng.g4.course.Course; +import softeng.g4.course.CourseList; + +import static org.junit.jupiter.api.Assertions.*; + +class AdminTest { + + private UserList userList; + private CourseList courseList; + private Admin testAdmin; + private TeachingAssistant testTa; + private Student testStudent; + + @BeforeEach + void setUpTearDown() { + userList = new UserList(); + courseList = new CourseList(); + + // This will add false users, for checking users in the arraylist. (NECESSARY) + new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); + new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); + new Admin("falseAdmin", "False Admin", userList); + + testAdmin = new Admin("testAdmin", "Test Admin", userList); + testTa = new TeachingAssistant("testTa", + "Test Teacher", Long.parseLong("123456789"), userList); + testStudent = new Student("testStudent", + "Test Student", Long.valueOf("123456789"), userList); + } + + @Test + void assignRole() { + } + + @Test + void setCourseTA() { + } + + @Test + void createCourse() { + } + + @Test + void seeCourseList() { + } + + @Test + void getUserList() { + } + + @Test + void seeAppointment() { + } + + @Test + void seeCalendar() { + } + + @Test + void testToString() { + } + + @Test + void getRole() { + } + + @Test + void getUsername() { + } + + @AfterEach + void finalTearDown() { + courseList = new CourseList(); + userList = new UserList(); + + // Uncomment here to add a new TA or Admin + // This will add false users, for checking users in the arraylist. (NECESSARY) + new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); + new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); + new Admin("falseAdmin", "False Admin", userList); + + // Add testStudent + new Student("akuStudent", "Aku Student", Long.valueOf("123456789"), userList); + + // Add testTa with a mock calendar and schedule + TeachingAssistant testTa = new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"), userList); + testTa.setSchedule("monday", "Free", "12:00", "17:00"); + testTa.setSchedule("tuesday", "Free", "08:00", "11:00"); + testTa.setSchedule("tuesday", "Free", "12:00", "15:00"); + testTa.setSchedule("saturday", "Busy", "07:00", "21:00"); + testTa.setSchedule("sunday", "Free", "12:00", "17:00"); + new TeachingAssistant("anotherTA", "Another TA", Long.valueOf("1"), userList); + + // Add testAdmin + new Admin("akuAdmin", "Aku Admin", userList); + + // Add false course + new Course("False Course", "FALSECOURSE", "False Professor", 0, courseList); + + // Add mock courses + new Course("Mata Kuliah", "MATKUL420", "Aku Dosen", 4, courseList); + new Course("Software Engineering", "SOFTENG2021", "Aku Professor", 3, courseList); + new Course("Fisika", "PHYS101", "Aku Dosen Fisika", 4, courseList); + + // Save the course + ListIO.saveList(courseList, userList); + } +} \ No newline at end of file diff --git a/src/test/java/softeng/g4/user/StudentTest.java b/src/test/java/softeng/g4/user/StudentTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c122963aa639b24bb83157df1a28b377c39d9c73 --- /dev/null +++ b/src/test/java/softeng/g4/user/StudentTest.java @@ -0,0 +1,95 @@ +package softeng.g4.user; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import softeng.g4.cli.ListIO; +import softeng.g4.course.Course; +import softeng.g4.course.CourseList; + +import static org.junit.jupiter.api.Assertions.*; + +class StudentTest { + + private UserList userList; + private CourseList courseList; + private Admin testAdmin; + private TeachingAssistant testTa; + private Student testStudent; + + @BeforeEach + void setUpTearDown() { + userList = new UserList(); + courseList = new CourseList(); + + // This will add false users, for checking users in the arraylist. (NECESSARY) + new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); + new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); + new Admin("falseAdmin", "False Admin", userList); + + testAdmin = new Admin("testAdmin", "Test Admin", userList); + testTa = new TeachingAssistant("testTa", + "Test Teacher", Long.parseLong("123456789"), userList); + testStudent = new Student("testStudent", + "Test Student", Long.valueOf("123456789"), userList); + } + + @Test + void setAppointment() { + } + + @Test + void seeCalendar() { + } + + @Test + void getRole() { + } + + @Test + void getUsername() { + } + + @Test + void testToString() { + } + + @AfterEach + void finalTearDown() { + courseList = new CourseList(); + userList = new UserList(); + + // Uncomment here to add a new TA or Admin + // This will add false users, for checking users in the arraylist. (NECESSARY) + new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); + new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); + new Admin("falseAdmin", "False Admin", userList); + + // Add testStudent + new Student("akuStudent", "Aku Student", Long.valueOf("123456789"), userList); + + // Add testTa with a mock calendar and schedule + TeachingAssistant testTa = new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"), userList); + testTa.setSchedule("monday", "Free", "12:00", "17:00"); + testTa.setSchedule("tuesday", "Free", "08:00", "11:00"); + testTa.setSchedule("tuesday", "Free", "12:00", "15:00"); + testTa.setSchedule("saturday", "Busy", "07:00", "21:00"); + testTa.setSchedule("sunday", "Free", "12:00", "17:00"); + new TeachingAssistant("anotherTA", "Another TA", Long.valueOf("1"), userList); + + // Add testAdmin + new Admin("akuAdmin", "Aku Admin", userList); + + // Add false course + new Course("False Course", "FALSECOURSE", "False Professor", 0, courseList); + + // Add mock courses + new Course("Mata Kuliah", "MATKUL420", "Aku Dosen", 4, courseList); + new Course("Software Engineering", "SOFTENG2021", "Aku Professor", 3, courseList); + new Course("Fisika", "PHYS101", "Aku Dosen Fisika", 4, courseList); + + // Save the course + ListIO.saveList(courseList, userList); + } +} \ No newline at end of file diff --git a/src/test/java/softeng/g4/user/TeachingAssistantTest.java b/src/test/java/softeng/g4/user/TeachingAssistantTest.java index 8fe1ee69257ee985a358970aace83d96d21f17eb..9f6261b3df3ad73ef6d5159589c0934166d68408 100644 --- a/src/test/java/softeng/g4/user/TeachingAssistantTest.java +++ b/src/test/java/softeng/g4/user/TeachingAssistantTest.java @@ -1,55 +1,153 @@ package softeng.g4.user; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import softeng.g4.cli.ListIO; +import softeng.g4.course.Course; import softeng.g4.course.CourseList; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + import static org.junit.jupiter.api.Assertions.*; class TeachingAssistantTest { - private UserList userList = new UserList(); - private CourseList courseList = new CourseList(); - private TeachingAssistant testTa = - new TeachingAssistant("testTa", "Test Teacher", Long.parseLong("123456789"), userList); + private UserList userList; + private CourseList courseList; + private Admin testAdmin; + private TeachingAssistant testTa; + private Student testStudent; - @Test - void seeCourseList() { + @BeforeEach + void setUpTearDown() { + userList = new UserList(); + courseList = new CourseList(); + + // This will add false users, for checking users in the arraylist. (NECESSARY) + new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); + new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); + new Admin("falseAdmin", "False Admin", userList); + + testAdmin = new Admin("testAdmin", "Test Admin", userList); + testTa = new TeachingAssistant("testTa", + "Test Teacher", Long.parseLong("123456789"), userList); + testStudent = new Student("testStudent", + "Test Student", Long.valueOf("123456789"), userList); } @Test void setSchedule() { -// Calendar testCalendar = new Calendar(); -// Schedule testSchedule = new Schedule("Busy", "07:00", "21:00"); -// testCalendar.addSchedule("saturday", new Schedule("Busy", "07:00", "21:00")); -// testTa.setSchedule("saturday", "Busy", "07:00", "21:00"); -// assertEquals(testTa.getCalendar().getSaturday().size(), 1); + testTa.setSchedule("monday", "Busy", "07:00", "21:00"); + testTa.setSchedule("tuesday", "Busy", "07:00", "21:00"); + testTa.setSchedule("wednesday", "Busy", "07:00", "21:00"); + testTa.setSchedule("thursday", "Busy", "07:00", "21:00"); + testTa.setSchedule("friday", "Busy", "07:00", "21:00"); + testTa.setSchedule("saturday", "Busy", "07:00", "21:00"); + testTa.setSchedule("sunday", "Busy", "07:00", "21:00"); + assertEquals(testTa.getCalendar().getMonday().size(), 1); + assertEquals(testTa.getCalendar().getTuesday().size(), 1); + assertEquals(testTa.getCalendar().getWednesday().size(), 1); + assertEquals(testTa.getCalendar().getThursday().size(), 1); + assertEquals(testTa.getCalendar().getFriday().size(), 1); + assertEquals(testTa.getCalendar().getSaturday().size(), 1); + assertEquals(testTa.getCalendar().getSunday().size(), 1); } @Test - void seeCalendar() { + void seeCalendar() throws Exception { + ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + // After this all System.out.println() statements will come to outContent stream. + + testTa.setSchedule("monday", "Busy", "07:00", "21:00"); + testTa.setSchedule("tuesday", "Busy", "07:00", "21:00"); + testTa.setSchedule("wednesday", "Busy", "07:00", "21:00"); + testTa.setSchedule("thursday", "Busy", "07:00", "21:00"); + testTa.setSchedule("friday", "Busy", "07:00", "21:00"); + testTa.setSchedule("saturday", "Busy", "07:00", "21:00"); + testTa.setSchedule("sunday", "Busy", "07:00", "21:00"); + + testTa.seeCalendar(); + + // Remove all linebreaks from the print, since different environment uses different line separators + String outContentEdit = outContent.toString().replaceAll("\n", "").replaceAll("\r", ""); + + String expectedOutput = + "Monday:" + + "Busy 07:00 - 21:00" + + "Tuesday:" + + "Busy 07:00 - 21:00" + + "Wednesday:" + + "Busy 07:00 - 21:00" + + "Thursday:" + + "Busy 07:00 - 21:00" + + "Friday:" + + "Busy 07:00 - 21:00" + + "Saturday:" + + "Busy 07:00 - 21:00" + + "Sunday:" + + "Busy 07:00 - 21:00"; + + assertEquals(expectedOutput, outContentEdit); } @Test void acceptAppointment() { + testStudent.setAppointment( + "31/12", "testTa", "08:00", "09:40", "testDesc", userList); + testTa.acceptAppointment(testTa.appointmentList.get(0).getId(), userList); + assertEquals(testTa.appointmentList.get(0).getStatus(), "Accepted"); + assertEquals(testStudent.appointmentList.get(0).getStatus(),"Accepted"); } @Test void rejectAppointment() { + testStudent.setAppointment( + "31/12", "testTa", "08:00", "09:40", "testDesc", userList); + testTa.rejectAppointment(testTa.appointmentList.get(0).getId(), userList); + assertEquals(testTa.appointmentList.get(0).getStatus(), "Rejected"); + assertEquals(testStudent.appointmentList.get(0).getStatus(),"Rejected"); } - @Test - void addReminder() { - } + @AfterEach + void finalTearDown() { + courseList = new CourseList(); + userList = new UserList(); - @Test - void testToString() { - } + // Uncomment here to add a new TA or Admin + // This will add false users, for checking users in the arraylist. (NECESSARY) + new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList); + new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList); + new Admin("falseAdmin", "False Admin", userList); - @Test - void getRole() { - } + // Add testStudent + new Student("akuStudent", "Aku Student", Long.valueOf("123456789"), userList); - @Test - void getUsername() { + // Add testTa with a mock calendar and schedule + TeachingAssistant testTa = new TeachingAssistant("akuTA", "Aku Asdos", Long.valueOf("123456789"), userList); + testTa.setSchedule("monday", "Free", "12:00", "17:00"); + testTa.setSchedule("tuesday", "Free", "08:00", "11:00"); + testTa.setSchedule("tuesday", "Free", "12:00", "15:00"); + testTa.setSchedule("saturday", "Busy", "07:00", "21:00"); + testTa.setSchedule("sunday", "Free", "12:00", "17:00"); + new TeachingAssistant("anotherTA", "Another TA", Long.valueOf("1"), userList); + + // Add testAdmin + new Admin("akuAdmin", "Aku Admin", userList); + + // Add false course + new Course("False Course", "FALSECOURSE", "False Professor", 0, courseList); + + // Add mock courses + new Course("Mata Kuliah", "MATKUL420", "Aku Dosen", 4, courseList); + new Course("Software Engineering", "SOFTENG2021", "Aku Professor", 3, courseList); + new Course("Fisika", "PHYS101", "Aku Dosen Fisika", 4, courseList); + + // Save the course + ListIO.saveList(courseList, userList); } + } \ No newline at end of file diff --git a/tasc.iml b/tasc.iml index c90834f2d607afe55e6104d8aa2cdfffb713f688..78b2cc53b203f0b97534bb1184cdc7b474339fb4 100644 --- a/tasc.iml +++ b/tasc.iml @@ -1,11 +1,2 @@ <?xml version="1.0" encoding="UTF-8"?> -<module type="JAVA_MODULE" version="4"> - <component name="NewModuleRootManager" inherit-compiler-output="true"> - <exclude-output /> - <content url="file://$MODULE_DIR$"> - <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> - </content> - <orderEntry type="inheritedJdk" /> - <orderEntry type="sourceFolder" forTests="false" /> - </component> -</module> \ No newline at end of file +<module type="JAVA_MODULE" version="4" /> \ No newline at end of file