Fakultas Ilmu Komputer UI

Commit a000a782 authored by saddamonpc's avatar saddamonpc
Browse files

Add switch cases for student login

parent feb6a27a
......@@ -35,33 +35,33 @@ 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 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);
......@@ -91,20 +91,55 @@ public class Main {
}
// TODO: Maybe it is better to move this whole if block into a different class
String[] splited = {"", ""};
splited = q.split("\\s+");
String searchUsername = splited[1];
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("T")) {
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();
while (!q.equals("LOG OUT")) {
saveList(courseList, userList);
System.out.print("Input: ");
q = sc.nextLine();
switch (q) {
case "HELP":
introStudent();
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();
while (!q.equals("LOG OUT")) {
saveList(courseList, userList);
System.out.print("Input: ");
......@@ -149,14 +184,15 @@ public class Main {
if (currentAdmin.getUsername().equals("falseAdmin")) {
q = "LOG OUT";
System.out.println("Wrong username!");
}
} else introAdmin(currentAdmin);
while (!q.equals("LOG OUT")) {
saveList(courseList, userList);
System.out.print("Input: ");
q = sc.nextLine();
switch (q) {
case "HELP":
introAdmin();
introAdmin(currentAdmin);
break;
case "COURSELIST":
......@@ -202,7 +238,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("Login as (S)tudent / (T)eaching Assistant / (A)dmin?");
System.out.println("Login as (S)tudent <username> / (T)eaching Assistant <username> / (A)dmin <username> ?");
System.out.println();
}
......@@ -226,8 +262,8 @@ public class Main {
System.out.println("ADD SCHEDULE \t\t Add new schedule.");
}
public static void introAdmin() {
System.out.println("You are logged in as an admin.");
public static void introAdmin(Admin currentAdmin) {
System.out.println("You are logged in as an admin with a username " + 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.");
......
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