/** * @param userList * @return student Prompt username and password and find match, if no match give user option to * create a new account */ public static void login(LinkedList<User> userList, LinkedList<Course> courseList) { // Prompt user to login or terminate systems String input = ""; do { input = JOptionPane.showInputDialog( "Enter 1 to login, 2 for admin course addition, or 3 to exit system"); if (input.equals("3")) { JOptionPane.showMessageDialog(null, "Goodbye"); dataToFiles(courseList); } else if (input.equals("2")) { if (createAdmin()) { System.out.println("admincreated"); addCourse(courseList); } else if (input.equals("1")) { JOptionPane.showMessageDialog(null, "incorrect credentials"); login(userList, courseList); } } else if (input.equals("1")) { } else { JOptionPane.showMessageDialog(null, "Invalid selection, Try again."); } } while (!(input.equals("1"))); String username = JOptionPane.showInputDialog(null, "Enter username"); String password = JOptionPane.showInputDialog(null, "Please enter your password"); User aStudent = validateUsername(username, userList); System.out.print(validateUsername(username, userList)); // Loop through users and look for match, If non found, use 'registerStudenAccount' method to // create and return a student if (aStudent == null) { int selection = JOptionPane.showConfirmDialog( null, "Account does not exist\nWould you like to create a new account?\n'NO' to try another account 'YES' to create a new account", "title", JOptionPane.YES_NO_OPTION); if (selection == 1) { login(userList, courseList); } else if (selection == 0) { aStudent = registerStudentAccount(userList); } } // Alert use of incorrect passwords else { if (!(validatePassword(aStudent, password))) { do { password = JOptionPane.showInputDialog( "Incorrect password entered\nTry again or enter 'D' to return to main screen"); if (password.equalsIgnoreCase("D")) { login(userList, courseList); } } while (!(validatePassword(aStudent, password))); } } // if (aStudent.instancOf()) menu(courseList, aStudent, userList); }
/** * Prompt student with list of courses and add each on based on selection to their list of courses * * @param allCourses * @param aStudent */ public static void menu(LinkedList<Course> courseList, User aUser, LinkedList<User> userList) { int selection = -1; final int MAX_COURSES = 7; boolean more; // send user if admin to add course Student aStudent = new Student(); if (aUser instanceof Student) { aStudent = (Student) aUser; String menuPrompt = "Welcome to the GMU IT Bookstore!" + "\nPlease enter the number that corresponds to one of your classes"; for (int i = 0; i < courseList.size(); i++) { Course aCourse = courseList.get(i); menuPrompt += "\n" + (i + 1) + ") " + aCourse.getCourseName(); } do { do { try { selection = Integer.parseInt(JOptionPane.showInputDialog(menuPrompt)); if (selection > courseList.size() || selection <= 0) { throw new IllegalArgumentException(); } } catch (NumberFormatException e) { JOptionPane.showMessageDialog( null, "Invalid entry, please enter number associated with course"); selection = -1; } catch (IllegalArgumentException e) { JOptionPane.showMessageDialog(null, "Invalid Selection. Try again."); selection = -1; } } while (selection > courseList.size() || selection <= 0); // add a course to student list of courses if its not already added to student's courses if (aStudent.getCourseList().contains(courseList.get(selection - 1))) { JOptionPane.showMessageDialog(null, "You have already ordered this book"); } else if (aStudent.getCourseList().size() >= MAX_COURSES) { JOptionPane.showMessageDialog( null, "You have already registered " + MAX_COURSES + " courses, the max number allowed"); break; } else { if (courseList.get(selection - 1).getTextStock() < 1) { JOptionPane.showMessageDialog( null, "This book is backordered and will take extra processing time"); } Course aCourse = (courseList.get(selection - 1)); aStudent.addCourse(aCourse); JOptionPane.showMessageDialog( null, courseList.get(selection - 1).getCourseText() + " Has been added to your cart"); } // prompt student if they would like to continue entering courses int reply = JOptionPane.showConfirmDialog( null, "Do you have another class to enter?", "title", JOptionPane.YES_NO_OPTION); if (reply == 1) { more = false; } else { more = true; } } while (more && (aStudent.getCourseList().size() <= MAX_COURSES)); // Give confirmation of order JOptionPane.showMessageDialog(null, "Your order has been entered\n"); } else { // Admin tempAdmin; addCourse(courseList); } // return user to login screen login(userList, courseList); }