Fakultas Ilmu Komputer UI

Commit 52ade2ed authored by Mohammad Saddam Mashuri's avatar Mohammad Saddam Mashuri
Browse files

Merge branch 'saddam-gradle' into 'staging'

Merge current test progress to staging

See merge request !3
parents 275544e2 f609a713
Pipeline #81783 passed with stage
in 1 minute and 10 seconds
<?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
<?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
......@@ -22,6 +22,12 @@ dependencies {
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(14))
}
}
test {
useJUnitPlatform()
finalizedBy("jacocoTestReport")
......
......@@ -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();
}
......
......@@ -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;
}
}
......@@ -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;
}
}
}
......@@ -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();
}
......
......@@ -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;
......
......@@ -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();
}
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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
......
......@@ -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() {}