Fakultas Ilmu Komputer UI

Commit 25472367 authored by saddamonpc's avatar saddamonpc
Browse files

Add login feature and Update TODOs

parent a000a782
......@@ -12,22 +12,36 @@ 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" USE CASE
* TODO: Implement the methods in the Student class
* 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
* TODO: Implement a method to search for a user and log in (must implement the previous TODO to do this)
* 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 ONCE,
* then stop the program, and delete the code.
* Ex: New Student("exampleUsername", "Example Fullname", Long.valueOf("exampleNPM"), userList);
*/
/**
* TODOs for "APPOINTMENT" USE CASE
* TODO: Implement the methods in the Appointment class
* TODO: Implement the methods in the RequestAppointment class
* 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) {
......@@ -35,37 +49,46 @@ public class Main {
String q = "";
String currentLogin = "";
// // Uncomment all of this for the "hardcoded" version.
//
// // Uncomment to add a new fresh userList and courseList
// CourseList courseList = new CourseList();
// UserList userList = new UserList();
//
// // Uncomment here to add a new TA or Admin
// Student falseStudent =
// new Student("falseStudent", "False Student", Long.valueOf("123456789"), userList);
// TeachingAssistant falseTeachingAssistant =
// new TeachingAssistant("falseTA", "False TA", Long.valueOf("123456789"), userList);
// Admin falseAdmin =
// new Admin("falseAdmin", "False Admin", userList);
// 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);
// Admin testAdmin = new Admin("akuAdmin", "Aku Admin", userList);
// saveList(courseList, userList);
// Open all persistent storage
CourseList courseList = openCourseList();
UserList userList = openUserList();
//
// // Uncomment to do testing
// TeachingAssistant testTa = (TeachingAssistant) userList.userList.get(0);
// Admin testAdmin = (Admin) userList.userList.get(1);
// -------- Uncomment all of this for the "hardcoded" version.
// Uncomment to add a new fresh userList and courseList
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
saveList(courseList, userList);
// // Open all persistent storage
// CourseList courseList = openCourseList();
// UserList userList = openUserList();
// // Store userList test
// try {
......@@ -112,15 +135,20 @@ public class Main {
if (currentStudent.getUsername().equals("falseStudent")) {
q = "LOG OUT";
System.out.println("Wrong username!");
} else introStudent();
} 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);
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();
introStudent(currentStudent);
break;
case "CALENDAR":
// TODO: Make this such that users can see TA's calendar by inputting their username
currentStudent.seeCalendar();
break;
case "LOG OUT":
......@@ -138,15 +166,15 @@ public class Main {
if (currentTA.getUsername().equals("falseTA")) {
q = "LOG OUT";
System.out.println("Wrong username!");
} else introTA();
} 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);
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();
introTA(currentTA);
break;
case "CALENDAR":
......@@ -184,10 +212,10 @@ public class Main {
if (currentAdmin.getUsername().equals("falseAdmin")) {
q = "LOG OUT";
System.out.println("Wrong username!");
} else introAdmin(currentAdmin);
} 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);
saveList(courseList, userList); // Saves the list everytime the user is in the "Main menu"
System.out.print("Input: ");
q = sc.nextLine();
switch (q) {
......@@ -216,8 +244,22 @@ public class Main {
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("Not yet available.");
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":
......@@ -246,31 +288,38 @@ public class Main {
//
// }
public static void introStudent() {
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 Show available commands.");
System.out.println("CALENDAR <TA's NPM> \t\t\t See TA's calendar.");
System.out.println("CALENDAR \t\t See this temporary student's calendar.");
System.out.println();
}
public static void introTA() {
System.out.println("You are logged in as a teaching assistant.");
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("COURSE DETAILS \t\t See course details with the right courseId.");
System.out.println("ADD SCHEDULE \t\t Add new schedule.");
System.out.println();
}
public static void introAdmin(Admin currentAdmin) {
System.out.println("You are logged in as an admin with a username " + currentAdmin.getUsername() + ".");
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
......
......@@ -9,8 +9,8 @@ import java.util.ArrayList;
public class Course implements Serializable {
private String name;
private String courseId;
private ArrayList<Student> students;
private ArrayList<TeachingAssistant> teachingAssistants;
private ArrayList<Student> students = new ArrayList<Student>();
private ArrayList<TeachingAssistant> teachingAssistants = new ArrayList<TeachingAssistant>();
private String professor;
private int sks;
private boolean adminPermission;
......@@ -31,6 +31,20 @@ public class Course implements Serializable {
this.teachingAssistants.add(ta);
}
// Prints course details
public void getCourseDetail() {
System.out.println(name + " - " + courseId);
System.out.println("Professor: " + professor);
System.out.println("SKS: " + sks);
System.out.println("Responsible TA(s):");
for (TeachingAssistant ta : teachingAssistants) System.out.println(ta);
}
public String getCourseId() {
return courseId;
}
// toString() method to print the course in an orderly manner
public String toString() {
return name + " - " + courseId + " | Professor: " + professor + " | SKS: " + sks;
}
......
package softeng.g4.course;
import softeng.g4.user.Student;
import softeng.g4.user.User;
import java.io.Serializable;
import java.util.ArrayList;
public class CourseList implements Serializable {
public ArrayList<Course> courseList = new ArrayList<Course>();
// Shows the course list in an orderly manner
public void showCourseList() {
for (int i = 1; i < courseList.size(); i++) {
System.out.println(courseList.get(i));
}
System.out.println();
}
// Returns the corresponding course, if found.
public Course searchCourse(String courseId) {
for (Course course : courseList) {
System.out.println(course);
// Linear search courses by their courseId
if (course.getCourseId().equals(courseId)) {
return course;
}
}
// Returns a course called False Course, so user will have to search the course with the correct course name
return courseList.get(0);
}
}
package softeng.g4.user;
import softeng.g4.appointment.Appointment;
import softeng.g4.course.Course;
import softeng.g4.course.CourseList;
......@@ -17,11 +18,17 @@ public class Admin extends User {
userList.userList.add(this);
}
public void assignRole() {}
// 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) {
course.setTA(ta);
if (ta.getUsername().equals("falseTA") || course.getCourseId().equals("FALSECOURSE")) {
System.out.println("Wrong TA or CourseId. Try again.");
} else {
System.out.println("Teaching Assistant " + ta.getUsername() + " has successfully assigned to course " + course.getCourseId());
course.setTA(ta);
}
}
// Create course
......@@ -34,16 +41,28 @@ public class Admin extends User {
courseList.showCourseList();
}
public void seeAppointment() {}
// Shows all the users except for the false users
public void getUserList(UserList userList) {
for (User user: userList.userList) {
System.out.println(user);
for (int i = 3; i < userList.userList.size(); i++) {
System.out.println(userList.userList.get(i));
}
System.out.println();
// Uncomment to include the printing of the false users
// for (User user: userList.userList) {
// System.out.println(user);
// }
}
public void seeSchedule() {}
// TODO: Iteration 3 - Admin can see the appointment, if appointment has the permission true
public void seeAppointment(Appointment ap) {}
// TODO: Iteration 3 - Admin can see the TA's calendar, if calendar has the permission true
public void seeCalendar(TeachingAssistant ta) {}
public String toString() {
return username;
return username + " - " + fullname;
}
public String getRole() {
......
package softeng.g4.user;
import softeng.g4.calendar.Calendar;
public class Student extends UserStudent {
private String username;
private String fullname;
......@@ -17,10 +19,21 @@ public class Student extends UserStudent {
userList.userList.add(this);
}
// TODO: Adds appointment with the corresponding TeachingAssistant
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() {}
public void seeCalendar(long npm) {}
// 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 String getRole() {
return role;
......@@ -29,4 +42,9 @@ public class Student extends UserStudent {
public String getUsername() {
return username;
}
public String toString() {
return username + " - " + fullname;
}
}
......@@ -37,12 +37,16 @@ public class TeachingAssistant extends UserStudent {
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() {}
// Not a necessary method to implement. Just a bonus if there's enough time.
public void addReminder() {}
public String toString() {
return username;
return username + " - " + fullname;
}
public String getRole() {
......
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