Fakultas Ilmu Komputer UI

Commit 5f971bc7 authored by saddamonpc's avatar saddamonpc
Browse files

Separate the switch block in Main.java to each respective CLI subclasses

parent 426926fe
......@@ -2,7 +2,10 @@ 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;
import softeng.g4.cli.TACLI;
import softeng.g4.course.Course;
import softeng.g4.course.CourseList;
import softeng.g4.user.*;
......@@ -53,51 +56,51 @@ 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 all of this for the "hardcoded" version.
// Uncomment to add a new fresh userList and courseList
courseList = new CourseList();
userList = new UserList();
// PRODUCTION BUILD: Open all persistent storage
courseList = ListIO.openCourseList();
userList = ListIO.openUserList();
// 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
while (true) {
// PRODUCTION BUILD: Open all persistent storage
courseList = ListIO.openCourseList();
userList = ListIO.openUserList();
intro();
q = sc.nextLine();
......@@ -124,194 +127,40 @@ public class Main {
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")) {
ListIO.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")) {
ListIO.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")) {
ListIO.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;
}
}
switch (currentLogin) {
case "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
// If we reach here, that means we found the user, and we are now logged in.
StudentCLI.main(new String[]{searchUsername});
break;
case "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
// If we reach here, that means we found the user, and we are now logged in.
TACLI.main(new String[]{searchUsername});
break;
case "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
// If we reach here, that means we found the user, and we are now logged in.
AdminCLI.main(new String[]{searchUsername});
break;
}
}
}
......@@ -323,46 +172,4 @@ public class Main {
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();
}
}
package softeng.g4.cli;
public class AdminCLI {
import softeng.g4.course.Course;
import softeng.g4.course.CourseList;
import softeng.g4.user.Admin;
import softeng.g4.user.UserList;
import java.util.Scanner;
public class AdminCLI extends CLI {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
UserList userList = ListIO.openUserList();
CourseList courseList = ListIO.openCourseList();
Admin currentAdmin = userList.searchAdmin(args[0]);
String q = "";
intro(currentAdmin);
while (!q.equals("LOG OUT")) {
// Saves the list everytime the user is in the "Main menu"
ListIO.saveList(courseList, userList);
System.out.print("Input: ");
q = sc.nextLine();
switch (q) {
case "HELP":
intro(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(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();
}
}
package softeng.g4.cli;
public abstract class CLI {
}
package softeng.g4.cli;
public class StudentCLI {
import softeng.g4.appointment.Appointment;
import softeng.g4.course.CourseList;
import softeng.g4.user.Student;
import softeng.g4.user.TeachingAssistant;
import softeng.g4.user.UserList;
import java.util.Scanner;
public class StudentCLI extends CLI {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
UserList userList = ListIO.openUserList();
CourseList courseList = ListIO.openCourseList();
Student currentStudent = userList.searchStudent(args[0]);
String q = "";
intro(currentStudent);
while (!q.equals("LOG OUT")) {
ListIO.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":
intro(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;
}
}
}
public static void intro(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();
}
}
package softeng.g4.cli;
public class TACLI {
import softeng.g4.appointment.Appointment;
import softeng.g4.course.CourseList;
import softeng.g4.user.TeachingAssistant;
import softeng.g4.user.UserList;
import java.util.Scanner;
public class TACLI extends CLI {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
UserList userList = ListIO.openUserList();
CourseList courseList = ListIO.openCourseList();
TeachingAssistant currentTA = userList.searchTA(args[0]);
String q = "";
intro(currentTA);
while (!q.equals("LOG OUT")) {
// Saves the list everytime the user is in the "Main menu"
ListIO.saveList(courseList, userList);
System.out.print("Input: ");
q = sc.nextLine();
switch (q) {
case "HELP":
intro(currentTA);
break;
case "CALENDAR":
currentTA.seeCalendar();
break;