Fakultas Ilmu Komputer UI

Commit ceb1c4ef authored by Kevin Muhammad Afiza Kurniawan's avatar Kevin Muhammad Afiza Kurniawan
Browse files

Appointment

parent 9298b8e5
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.*;
......@@ -145,9 +147,35 @@ public class Main {
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 name: ");
// Student name = sc.nextLine();
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("Sucessfully 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
currentStudent.seeCalendar();
System.out.println("Enter TA's Username: ");
currentStudent.seeCalendar(sc.nextLine(), userList);
break;
case "LOG OUT":
......@@ -197,6 +225,23 @@ public class Main {
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;
......@@ -291,8 +336,10 @@ public class Main {
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 Show available commands.");
System.out.println("CALENDAR \t\t See this temporary student's calendar.");
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();
}
......@@ -305,6 +352,9 @@ public class Main {
System.out.println("COURSELIST \t\t\t See all courses.");
System.out.println("COURSE DETAILS \t\t See course details with the right courseId.");
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();
}
......
package softeng.g4.appointment;
public class 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;
}
}
package softeng.g4.calendar;
import softeng.g4.appointment.Appointment;
import java.io.Serializable;
import java.util.ArrayList;
......@@ -11,6 +13,13 @@ 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<>();
public void showCalendar() {
System.out.println("Monday:");
......@@ -81,4 +90,41 @@ public class Calendar implements Serializable {
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;
// }
// }
}
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) {
......@@ -20,7 +26,20 @@ public class Student extends UserStudent {
}
// TODO: Adds appointment with the corresponding TeachingAssistant
public void addAppointment() {}
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);
System.out.println("Appointment's successfully added");
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() {}
......@@ -31,8 +50,10 @@ public class Student extends UserStudent {
// See this Student's calendar
// temporary calendar
// TODO: Change this method such that it returns the TA's calendar by searching for their username
private Calendar calendar = new Calendar();
public void seeCalendar() {this.calendar.showCalendar();}
public void seeCalendar(String TAusername, UserList userList) {
TeachingAssistant ta = userList.searchTA(TAusername);
ta.seeCalendar();
}
public String getRole() {
......
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) {
......@@ -33,14 +37,57 @@ 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();
}
// TODO: Implement these 2 methods such that they can change the status of the appointment to accepted or rejected
public void acceptAppointment() {}
public void rejectAppointment() {}
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() {}
......
Supports Markdown
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