Fakultas Ilmu Komputer UI

Commit 18b9f5de authored by saddamonpc's avatar saddamonpc
Browse files

Remove unused directory

parent 245e1117
Pipeline #81703 passed with stage
in 3 minutes and 18 seconds
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");
}
}
}
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;
}
}
package softeng.g4.appointment;
public class Reminder {
}
package softeng.g4.appointment;
public class RequestAppointment {
}
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);