Fakultas Ilmu Komputer UI

Commit 71d9c904 authored by saddamonpc's avatar saddamonpc
Browse files

Change public modifiers to private and add reset() function in Main.java

parent dedb7e8f
Pipeline #82657 passed with stage
in 1 minute and 2 seconds
package softeng.g4;
import jdk.swing.interop.SwingInterOpUtils;
import softeng.g4.appointment.Appointment;
import softeng.g4.cli.AdminCLI;
import softeng.g4.cli.ListIO;
import softeng.g4.cli.StudentCLI;
......@@ -10,45 +8,10 @@ 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 = "";
......@@ -56,44 +19,8 @@ public class Main {
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
// ListIO.saveList(courseList, userList);
//
// // ---------------- END OF "HARDCODED" VERSION
// --------Uncomment this for the "hardcoded" version.
// reset();
while (true) {
......@@ -111,7 +38,6 @@ public class Main {
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;
......@@ -224,4 +150,42 @@ public class Main {
System.out.println();
}
// Function to reset the list to its factory new state
public static void reset() {
CourseList courseList = new CourseList();
UserList 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);
}
}
......@@ -44,7 +44,7 @@ public class StudentCLI extends CLI {
break;
case "APPOINTMENTS":
for (Appointment appointment : currentStudent.appointmentList) {
for (Appointment appointment : currentStudent.getAppointmentList()) {
System.out.println(appointment);
System.out.println();
}
......
......@@ -40,7 +40,6 @@ public class TACLI extends CLI {
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: ");
......@@ -53,7 +52,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.getAppointmentList()) {
System.out.println(appointment);
System.out.println();
}
......
......@@ -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>();
private ArrayList<Appointment> appointmentList = new ArrayList<Appointment>();
// Constructor
......@@ -25,7 +25,7 @@ public class Student extends UserStudent {
userList.userList.add(this);
}
// TODO: Adds appointment with the corresponding TeachingAssistant
// Adds appointment with the corresponding TeachingAssistant
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")){
......@@ -34,13 +34,11 @@ public class Student extends UserStudent {
Appointment newAppointment = new Appointment(date, this, ta, startTime, endTime, description);
//this.calendar.addAppointment(day, newAppointment);
this.appointmentList.add(newAppointment);
ta.appointmentList.add(newAppointment);
ta.getAppointmentList().add(newAppointment);
}
}
// See this Student's calendar
// temporary calendar
// TODO: Change this method such that it returns the TA's calendar by searching for their username
// See Teaching Assistant's calendar
public void seeCalendar(String TAusername, UserList userList) {
TeachingAssistant ta = userList.searchTA(TAusername);
ta.seeCalendar();
......@@ -59,4 +57,8 @@ public class Student extends UserStudent {
return username + " - " + fullname;
}
public ArrayList<Appointment> getAppointmentList() {
return this.appointmentList;
}
}
......@@ -14,7 +14,7 @@ public class TeachingAssistant extends UserStudent {
private long npm;
private Admin askPermissionAdmin = null;
private Calendar calendar = new Calendar();
public ArrayList<Appointment> appointmentList = new ArrayList<Appointment>();
private ArrayList<Appointment> appointmentList = new ArrayList<Appointment>();
// Constructor
public TeachingAssistant(String username, String fullname, long npm, UserList userList) {
......@@ -43,7 +43,7 @@ public class TeachingAssistant extends UserStudent {
this.calendar.showCalendar();
}
// TODO: Implement these 2 methods such that they can change the status of the appointment to accepted or rejected
// Accept appointment
public void acceptAppointment(String id, UserList userList) {
boolean found = false;
for (Appointment appointment : appointmentList) {
......@@ -51,7 +51,7 @@ public class TeachingAssistant extends UserStudent {
found = true;
appointment.setStatus("Accepted");
Student student = userList.searchStudent(appointment.getStudent().getUsername());
for (Appointment studentappointment : student.appointmentList) {
for (Appointment studentappointment : student.getAppointmentList()) {
if (studentappointment.getId().equals(id)) {
studentappointment.setStatus("Accepted");
}
......@@ -65,6 +65,7 @@ public class TeachingAssistant extends UserStudent {
}
}
// Reject appointment
public void rejectAppointment(String id, UserList userList) {
boolean found = false;
for (Appointment appointment : appointmentList) {
......@@ -72,7 +73,7 @@ public class TeachingAssistant extends UserStudent {
found = true;
appointment.setStatus("Rejected");
Student student = userList.searchStudent(appointment.getStudent().getUsername());
for (Appointment studentappointment : student.appointmentList) {
for (Appointment studentappointment : student.getAppointmentList()) {
if (studentappointment.getId().equals(id)) {
studentappointment.setStatus("Rejected");
}
......@@ -121,4 +122,8 @@ public class TeachingAssistant extends UserStudent {
public Calendar getCalendar() {
return calendar;
}
public ArrayList<Appointment> getAppointmentList() {
return this.appointmentList;
}
}
......@@ -98,18 +98,18 @@ class TeachingAssistantTest {
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");
testTa.acceptAppointment(testTa.getAppointmentList().get(0).getId(), userList);
assertEquals(testTa.getAppointmentList().get(0).getStatus(), "Accepted");
assertEquals(testStudent.getAppointmentList().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");
testTa.rejectAppointment(testTa.getAppointmentList().get(0).getId(), userList);
assertEquals(testTa.getAppointmentList().get(0).getStatus(), "Rejected");
assertEquals(testStudent.getAppointmentList().get(0).getStatus(),"Rejected");
}
@AfterEach
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment