Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.ArrayList;
- import java.util.Scanner;
- // USER LOGINS IN TEXT FILE "UserAccounts"
- public class HRApplication {
- // Text file that contains the logins for accounts
- public static final String AccountFile = "UserAccounts";
- public static final String staffLising = "casualStaffListing";
- // Array that hold the details for accounts
- private static ArrayList<Staff> accounts = new ArrayList<Staff>();
- // Array that holds course details
- private static ArrayList<Course> array = new ArrayList<Course>();
- private static ArrayList<CasualStaff> Listing = new ArrayList<CasualStaff>();
- public static void main(String[] args) {
- try {
- UserAccounts();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- // This method Reads the username and passwords for each user from textfile
- // "UserAccount"
- public static void UserAccounts() throws FileNotFoundException {
- // Creats objects and adds to array list.
- Scanner input = new Scanner(new File(AccountFile));
- while (input.hasNextLine()) { // Loops as long as there is another line
- String line = input.nextLine();
- // Checks if the data is for Admin, creats admin object
- if (line.equals("ADMIN")) {
- String AdminUsername = input.nextLine();
- String AdminPassword = input.nextLine();
- Admin admin = new Admin(AdminUsername, AdminPassword);
- accounts.add(admin);
- }
- if (line.equals("COORDINATOR")) {
- String coordinatorUsername = input.nextLine();
- String coordinatorPassword = input.nextLine();
- String coordinatorName = input.nextLine();
- String coordinatorSubject = input.nextLine();
- String coordinatorSubjectID = input.nextLine();
- Coordinator coordinator = new Coordinator(coordinatorUsername, coordinatorPassword, coordinatorName,
- coordinatorSubject, coordinatorSubjectID);
- accounts.add(coordinator);
- }
- if (line.equals("APPROVER")) {
- String approverUsername = input.nextLine();
- String approverPassword = input.nextLine();
- Approver approver = new Approver(approverUsername, approverPassword);
- accounts.add(approver);
- }
- }
- casualStaffListing();
- }
- public static void casualStaffListing() throws FileNotFoundException {
- Scanner input = new Scanner(new File(staffLising));
- while (input.hasNextLine()) {
- String line = input.nextLine();
- if (line.equals("Casual")) {
- String staffID = input.nextLine();
- String staffName = input.nextLine();
- boolean staffMonday = input.nextBoolean();
- boolean staffTuesday = input.nextBoolean();
- boolean staffWednesday = input.nextBoolean();
- boolean staffThursday = input.nextBoolean();
- boolean staffFriday = input.nextBoolean();
- String staffSubjectID = input.next();
- CasualStaff staffListing = new CasualStaff(staffID, staffName, staffMonday, staffTuesday,
- staffWednesday, staffThursday, staffFriday, staffSubjectID);
- Listing.add(staffListing);
- }
- }
- loginSystem();
- }
- // Adds the login details of the users into the system
- // public static void seedLogins() {
- // // Since there's only one user for each of these staff members, the log
- // // in details are stored in an array
- // Admin admin = new Admin("Admin", "cat");
- // Approver approver = new Approver("Approver", "dog");
- // Coordinator coordinator = new Coordinator("Coordinator", "mouse");
- // accounts.add(admin);
- // accounts.add(approver);
- // accounts.add(coordinator);
- // loginSystem();
- // }
- // This is the Login driver method, It prompts the users to enter their
- // username and passwords
- public static void loginSystem() {
- boolean idExist = false;
- Scanner input = new Scanner(System.in);
- System.out.printf("%-15s %s", "Please enter Username:", "");
- String usernameInput = input.nextLine();
- System.out.printf("%-15s %s", "Please enter Password:", "");
- String passwordInput = input.nextLine();
- // Loops through the array list to match the username and password
- for (int i = 0; i < accounts.size(); i++) {
- if (usernameInput.equals(accounts.get(i).getUsername())) {
- if (passwordInput.equals(accounts.get(i).getPassword())) {
- idExist = true;
- // Checks if the account details are for which user
- if (accounts.get(i) instanceof Admin) {
- Admin.menuChoice();
- } else if (accounts.get(i) instanceof Approver) {
- Approver.menuChoice();
- } else if (accounts.get(i) instanceof Coordinator) {
- Coordinator.menuChoice();
- }
- }
- }
- }
- // If account details dont exist, prompts user to try again
- System.out.println("Username or password is incorrect, please try again");
- loginSystem(); // Restarts the method
- input.close();
- }
- // Method for the addCourse option in the admin menu
- public static void addCourse() {
- Scanner user_input = new Scanner(System.in);
- // input course name
- System.out.printf("%-35s %s", "Enter Course Name:", "");
- String Coursename = user_input.nextLine();
- // input vehicle Height checks if its numeric
- System.out.printf("%-35s %s", "Please Course ID:", "");
- String CourseID = user_input.nextLine();
- System.out.printf("%-35s %s", "Enter pay rates per hour:", "");
- int Coursepay = user_input.nextInt();
- // Creats object for the course and adds to course array
- Course newCourse = new Course(Coursename, CourseID, Coursepay);
- array.add(newCourse);
- System.out.printf("New Course created successfully for %s !%n", Coursename);
- Admin.menuChoice();
- user_input.close();
- }
- // Method for the Alloction option in the admin menu
- public static void addCoordinator() {
- Scanner user_input = new Scanner(System.in);
- String cID = null;
- String Course_name = null;
- int Course_pay = 0;
- System.out.printf("%-35s %s", "Enter course ID:", "");
- cID = user_input.nextLine();
- // Checking if registration id already exist
- boolean cIDExists = false;
- for (Course g : array) {
- if ((cID.equals(g.getCourse_ID()))) {
- cIDExists = true;
- Course_name = g.getCourse_ID();
- Course_pay = g.getCourse_pay();
- }
- }
- if (cIDExists) {
- System.out.printf("%-35s %s", "Enter coordinator ID:", "");
- String CoordID = user_input.nextLine();
- for (int i = 0; i < accounts.size(); i++) {
- if (CoordID.equals((accounts.get(i)).getUsername())) {
- if (accounts.get(i) instanceof Coordinator) {
- // Makes object of the allocation and adds to array
- AllocateCoordinator newCoord = new AllocateCoordinator(Course_name, cID, Course_pay, CoordID);
- array.add(newCoord);
- System.out.printf("Successfully allocated for %s !%n", cID);
- Admin.menuChoice();
- user_input.close();
- } else {
- System.out.println("This ID does not belong to a coordinator");
- Admin.menuChoice();
- }
- }
- }
- System.out.println("ID does not exist");
- Admin.menuChoice();
- }
- }
- public static void allocateCasualStaff() {
- Scanner user_input = new Scanner(System.in);
- String courseDay = null;
- String cID = null;
- String Course_name = null;
- int Course_pay = 0;
- String staffID = null;
- boolean allocate = false;
- boolean staffExists = false;
- System.out.printf("%-35s %s", "Enter course ID:", "");
- cID = user_input.nextLine();
- // Checking if registration id already exist
- for (int i = 0; i < array.size(); i++) {
- if (cID.equals(array.get(i).getCourse_ID())) {
- Course_name = array.get(i).getCourse_ID();
- Course_pay = array.get(i).getCourse_pay();
- } else {
- System.out.println("Course ID does not exist");
- Coordinator.menuChoice();
- }
- System.out.println("Staff applications for this course");
- for (int a = 0; a < Listing.size(); a++) {
- if (cID.equals(Listing.get(a).getSubjectID()))
- System.out.println(Listing.get(a).getStaffDetails());
- }
- System.out.println("Please select which staff to allocate");
- staffID = user_input.nextLine();
- for (int c = 0; c < Listing.size(); c++) {
- if (staffID.equals(Listing.get(i).getID())) {
- staffExists = true;
- }
- }
- if (staffExists) {
- System.out.println("which day?");
- courseDay = user_input.nextLine();
- AllocateCasualStaff newStaff = new AllocateCasualStaff(Course_name, cID, Course_pay, staffID, courseDay,
- allocate);
- array.add(newStaff);
- System.out.printf("Successfully allocated for %s !%n", staffID);
- Admin.menuChoice();
- user_input.close();
- }
- }
- }
- public static void createTimetable() {
- Scanner user_input = new Scanner(System.in);
- String cID = null;
- String Course_name = null;
- int Course_pay = 0;
- String Coord_name = null;
- System.out.printf("%-35s %s", "Enter course ID:", "");
- cID = user_input.nextLine();
- // Checking if registration id already exist
- boolean cIDExists = false;
- for (Course g : array) {
- if ((cID.equals(g.getCourse_ID()))) {
- cIDExists = true;
- Course_name = g.getCourse_name();
- Course_pay = g.getCourse_pay();
- Coord_name = g.Coord_name();
- }
- }
- if (cIDExists) {
- String mondayTime = null;
- String tuesdayTime = null;
- String wednesdayTime = null;
- String thursdayTime = null;
- String fridayTime = null;
- System.out.println("Select true or false if the course is on this day");
- System.out.printf("%-35s %s", "Monday:", "");
- boolean mondayCourse = user_input.nextBoolean();
- if (mondayCourse) {
- System.out.printf("%-35s %s", "Course start Time:", "");
- String a = user_input.nextLine();
- mondayTime = user_input.nextLine();
- }
- System.out.printf("%-35s %s", "Tuesday:", "");
- boolean tuesdayCourse = user_input.nextBoolean();
- if (tuesdayCourse) {
- System.out.printf("%-35s %s", "Course start Time:", "");
- String a = user_input.nextLine();
- tuesdayTime = user_input.nextLine();
- }
- System.out.printf("%-35s %s", "Wednesday:", "");
- boolean wednesdayCourse = user_input.nextBoolean();
- if (wednesdayCourse) {
- System.out.printf("%-35s %s", "Course start Time:", "");
- String a = user_input.nextLine();
- wednesdayTime = user_input.nextLine();
- }
- System.out.printf("%-35s %s", "Thursday:", "");
- boolean thursdayCourse = user_input.nextBoolean();
- if (thursdayCourse) {
- System.out.printf("%-35s %s", "Course start Time:", "");
- String a = user_input.nextLine();
- thursdayTime = user_input.nextLine();
- }
- System.out.printf("%-35s %s", "Friday:", "");
- boolean fridayCourse = user_input.nextBoolean();
- if (fridayCourse) {
- System.out.printf("%-35s %s", "Course start Time:", "");
- String a = user_input.nextLine();
- fridayTime = user_input.nextLine();
- }
- createTimetable newTimetable = new createTimetable(Course_name, cID, Course_pay, Coord_name, mondayCourse,
- mondayTime, tuesdayCourse, tuesdayTime, wednesdayCourse, wednesdayTime, thursdayCourse,
- thursdayTime, fridayCourse, fridayTime); // Makes object of
- // the
- // allocation
- // and adds to
- // array
- array.add(newTimetable);
- System.out.printf("Successfully allocated time for %s !%n", cID);
- Coordinator.menuChoice();
- user_input.close();
- } else {
- System.out.println("no course ID found.");
- Coordinator.menuChoice();
- }
- }
- // Method for the report function in the admin menu Prints the details for
- // the course and coordinator allocated to the course
- public static void Report() {
- for (int i = 0; i < array.size(); i++) {
- // Steps through the array and prints the details
- System.out.println(array.get(i).getDetails());
- }
- Admin.menuChoice();
- }
- public static void ReportApproval() {
- for (int i = 0; i < array.size(); i++) {
- // Steps through the array and prints the details
- System.out.println(array.get(i).getDetails());
- }
- Approver.menuChoice();
- }
- public static void ReportCoordinator() {
- for (int i = 0; i < array.size(); i++) {
- // Steps through the array and prints the details
- System.out.println(array.get(i).getDetails());
- }
- Coordinator.menuChoice();
- }
- public static void ReportTimtable() {
- for (int i = 0; i < array.size(); i++) {
- // Steps through the array and prints the details
- System.out.println(array.get(i).getTimetabledetails());
- }
- Coordinator.menuChoice();
- }
- public static void ReportTimtableApprover() {
- for (int i = 0; i < array.size(); i++) {
- // Steps through the array and prints the details
- System.out.println(array.get(i).getTimetabledetails());
- }
- Approver.menuChoice();
- }
- public static void ReportTimtableAdmin() {
- for (int i = 0; i < array.size(); i++) {
- // Steps through the array and prints the details
- System.out.println(array.get(i).getTimetabledetails());
- }
- Admin.menuChoice();
- }
- // Logout function to restarts the program by calling the login method
- // prompts the user to login again
- public static void Logout() {
- loginSystem();
- }
- public static void CheckApproval() {
- // TODO Auto-generated method stub
- Scanner user_input = new Scanner(System.in);
- String cID = null;
- String Course_name = null;
- int Course_pay = 0;
- boolean Approve = false;
- System.out.printf("%-35s %s", "Enter course ID:", "");
- cID = user_input.nextLine();
- // Checking if registration id already exist
- boolean cIDExists = false;
- for (Course g : array) {
- if ((cID.equals(g.getCourse_ID()))) {
- cIDExists = true;
- Course_name = g.getCourse_ID();
- Course_pay = g.getCourse_pay();
- }
- }
- if (cIDExists) {
- System.out.printf("%-35s %s", "Approving course (true/false):", "");
- Approve = user_input.nextBoolean();
- ApprovingCourse newApproval = new ApprovingCourse(Course_name, cID, Course_pay, Approve);
- array.add(newApproval);
- System.out.printf("Successfully allocated for %s !%n", cID);
- Approver.menuChoice();
- user_input.close();
- } else {
- System.out.println("This ID does not belong to a coordinator");
- Approver.menuChoice();
- }
- }
- }
- // public static void allocateCasualStaff() {
- // Scanner user_input = new Scanner(System.in);cc
- //
- // String cID = null;
- //
- // System.out.printf("%-35s %s", "Enter course ID:", "");
- // cID = user_input.nextLine();
- //
- // // Checking if registration id already exist
- // boolean cIDExists = false;
- // for (Course g : array) {
- // if ((cID.equals(g.getCourse_ID()))) {
- // cIDExists = true;
- // }
- // }
- //
- // if (cIDExists) {
- // System.out.printf("%-35s %s", "Enter coordinator name:", "");
- // String Coord_name = user_input.nextLine();
- // // Makes object of the allocation and adds to array
- // array.add(newCoord);
- // AllocateCoordinator newCoord = new AllocateCoordinator(Course_name,
- // Course_ID, Course_pay, Coord_name);
- //
- // System.out.printf("Successfully allocated for %s !%n", Course_ID);
- //
- // Admin.menuChoice();
- // user_input.close();
- //
- // } else {
- // System.out.println("no course ID found.");
- // Admin.menuChoice();
- // }
- //
- // }
- //
- // }
- // Scanner user_input = new Scanner(System.in);
- // System.out.print("Are you sure you want to log out?");
- // String a = user_input.nextLine();
- //
- // String secondString = String.format("%-25s %s\n", "To Logout, Press:", "A");
- // String thirdString = String.format("%-25s %s\n", "TO cancel, Press:", "B");
- //
- // switch (a.toLowerCase()) {
- // case "a":
- // seedLogins();
- // break;
- // case "b":
- // Admin.menuChoice();
- // break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement