Advertisement
Guest User

Untitled

a guest
May 12th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.10 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5. // USER LOGINS IN TEXT FILE "UserAccounts"  
  6. public class HRApplication {
  7.  
  8.     public static final String AccountFile = "UserAccounts";        //Text file that contains the logins for accounts
  9.     private static ArrayList<Staff> accounts = new ArrayList<Staff>();      //Array that holds the login details for accounts
  10.     private static ArrayList<Course> array = new ArrayList<Course>();       //Array that holds course details
  11.  
  12.     public static void main(String[] args) {
  13.         try {
  14.             UserAccounts();    
  15.         } catch (FileNotFoundException e) {
  16.             // TODO Auto-generated catch block
  17.             e.printStackTrace();
  18.         }
  19.     }
  20.  
  21.    
  22.     public static void UserAccounts() throws FileNotFoundException{     //This method Reads the username and passwords for each user from textfile "UserAccount"
  23.         Scanner input = new Scanner(new File(AccountFile));             //Creats objects and adds to array list.
  24.        
  25.         while (input.hasNextLine()) {                                   //Loops as long as there is another line
  26.            
  27.             String line = input.nextLine();
  28.             if(line.equals("ADMIN")) {                                  //Checks if the data is for Admin, creats admin object
  29.                 String AdminUsername = input.nextLine();
  30.                 String AdminPassword = input.nextLine();
  31.                
  32.                 Admin admin = new Admin(AdminUsername, AdminPassword);
  33.                 accounts.add(admin);
  34.                
  35.             }  if(line.equals("COORDINATOR")){
  36.                 String coordinatorUsername = input.nextLine();
  37.                 String coordinatorPassword = input.nextLine();
  38.                
  39.                 Coordinator coordinator = new Coordinator(coordinatorUsername, coordinatorPassword);
  40.                 accounts.add(coordinator);
  41.  
  42.             } if(line.equals("APPROVER")){
  43.                 String approverUsername = input.nextLine();
  44.                 String approverPassword = input.nextLine();
  45.                
  46.                 Approver approver = new Approver(approverUsername, approverPassword);
  47.                 accounts.add(approver);
  48.  
  49.             } if(line.equals("CASUAL")){
  50.                 String casualUsername = input.nextLine();
  51.                 String casualPassword = input.nextLine();
  52.                
  53.                 CasualStaff casual = new CasualStaff(casualUsername, casualPassword);
  54.                 accounts.add(casual);
  55.  
  56.             }
  57.            
  58.         } loginSystem();
  59.     }
  60.    
  61.     // Adds the login details of the users into the system
  62. //  public static void seedLogins() {
  63. //      // Since there's only one user for each of these staff members, the log
  64. //      // in details are stored in an array
  65. //      Admin admin = new Admin("Admin", "cat");
  66. //      Approver approver = new Approver("Approver", "dog");
  67. //      Coordinator coordinator = new Coordinator("Coordinator", "mouse");
  68. //      accounts.add(admin);
  69. //      accounts.add(approver);
  70. //      accounts.add(coordinator);
  71. //      loginSystem();
  72. //  }
  73.  
  74.     public static void loginSystem() {                          //This is the Login driver method, It prompts the users to enter their username and passwords
  75.         boolean idExist = false;                               
  76.         Scanner input = new Scanner(System.in);
  77.         System.out.printf("%-15s %s", "Please enter Username:", "");
  78.         String usernameInput = input.nextLine();
  79.         System.out.printf("%-15s %s", "Please enter Password:", "");
  80.         String passwordInput = input.nextLine();
  81.  
  82.         for (int i = 0; i < accounts.size(); i++) {             //Loops through the array list to match the username and password
  83.  
  84.             if (usernameInput.equals(accounts.get(i).getUsername())) {
  85.                 if (passwordInput.equals(accounts.get(i).getPassword())) {
  86.                     idExist = true;
  87.  
  88.                     if (accounts.get(i) instanceof Admin) {     //Checks if the account details are for which user
  89.                         Admin.menuChoice();
  90.                     } else if (accounts.get(i) instanceof Approver) {
  91.                         Approver.menuChoice();
  92.                     } else if (accounts.get(i) instanceof Coordinator) {
  93.                         Coordinator.menuChoice();
  94.                     } else if (accounts.get(i) instanceof CasualStaff) {
  95.                         CasualStaff.menuChoice();
  96.                          
  97.                     }
  98.                 }
  99.             }
  100.         }
  101.  
  102.         System.out.println("Username or password is incorrect, please try again");      //If account details dont exist, prompts user to try again
  103.         loginSystem();                                                                  //Restarts the method
  104.         input.close();
  105.     }
  106.  
  107.      public static void addCourse() {                       //Method for the addCourse option in the admin menu
  108.          
  109.             Scanner user_input = new Scanner(System.in);
  110.      
  111.             // input course name
  112.             System.out.printf("%-35s %s", "Enter Course Name:", "");
  113.             String Course_name = user_input.nextLine();
  114.      
  115.             // input vehicle Height checks if its numeric
  116.             System.out.printf("%-35s %s", "Please Course ID:", "");
  117.             String Course_ID = user_input.nextLine();
  118.      
  119.             System.out.printf("%-35s %s", "Enter pay rates per hour:", "");
  120.             int Course_pay = user_input.nextInt();
  121.      
  122.             Course newCourse = new Course(Course_name, Course_ID, Course_pay);          //Creats object for the course and adds to course array
  123.             array.add(newCourse);
  124.      
  125.             System.out.printf("New Course created successfully for %s !%n", Course_name);
  126.      
  127.             Admin.menuChoice();
  128.             user_input.close();
  129.         }
  130.      
  131.         public static void addCoordinator() {           //Method for the Alloction option in the admin menu
  132.             Scanner user_input = new Scanner(System.in);
  133.      
  134.             String cID = null;
  135.             String Course_name = null;
  136.             int Course_pay = 0;
  137.      
  138.                 System.out.printf("%-35s %s", "Enter course ID:", "");
  139.                 cID = user_input.nextLine();
  140.      
  141.             // Checking if registration id already exist
  142.             boolean cIDExists = false;
  143.             for (Course g : array) {
  144.                 if ((cID.equals(g.getCourse_ID()))) {
  145.                     cIDExists = true;
  146.                     Course_name =g.getCourse_ID();
  147.                     Course_pay =g.getCourse_pay();
  148.                    
  149.            
  150.                 }
  151.             }
  152.      
  153.             if (cIDExists) {
  154.                
  155.                 System.out.printf("%-35s %s", "Enter coordinator name:", "");
  156.                 String Coord_name = user_input.nextLine();
  157.      
  158.                 AllocateCoordinator newCoord = new AllocateCoordinator(Course_name, cID, Course_pay,Coord_name); //Makes object of the allocation and adds to array
  159.                 array.add(newCoord);
  160.      
  161.                 System.out.printf("Successfully allocated for %s !%n", cID);
  162.      
  163.                 Admin.menuChoice();
  164.                 user_input.close();
  165.      
  166.      
  167.             } else {
  168.                 System.out.println("no course ID found.");
  169.                 Admin.menuChoice();
  170.             }
  171.      
  172.         }
  173.        
  174.         public static void  createTimetable() {
  175.             Scanner user_input = new Scanner(System.in);
  176.            
  177.               String cID = null;
  178.               String Course_name = null;
  179.               int Course_pay = 0;
  180.               String Coord_name = null;
  181.              
  182.      
  183.                  
  184.                 System.out.printf("%-35s %s", "Enter course ID:", "");
  185.                 cID = user_input.nextLine();
  186.      
  187.             // Checking if registration id already exist
  188.             boolean cIDExists = false;
  189.             for (Course g : array) {
  190.                 if ((cID.equals(g.getCourse_ID()))) {
  191.                     cIDExists = true;
  192.                     Course_name =g.getCourse_name();
  193.                     Course_pay =g.getCourse_pay();
  194.                     Coord_name =g.Coord_name();
  195.                 }
  196.             }  
  197.      
  198.             if (cIDExists) {
  199.                
  200.                  System.out.printf("%-35s %s", "Enter desired day:", "");
  201.                  String Course_day = user_input.nextLine();
  202.                  
  203.                  System.out.printf("%-35s %s", "Enter desired time (e.g 4:30 pm - 5:30 pm", "");
  204.                  String Course_time = user_input.nextLine();
  205.                
  206.                  createTimetable newTimetable = new createTimetable(Course_name, cID, Course_pay,Coord_name,Course_day,Course_time); //Makes object of the allocation and adds to array
  207.                     array.add(newTimetable);
  208.                    
  209.                     System.out.printf("Successfully allocated time for %s !%n", cID);
  210.                  
  211.                     Coordinator.menuChoice();
  212.                     user_input.close();
  213.          
  214.            
  215.         } else {
  216.            
  217.             System.out.println("no course ID found.");
  218.             Coordinator.menuChoice();
  219.            
  220.         }
  221.         }
  222.  
  223.     public static void Report() {       //Method for the report function in the admin menu
  224.                                         // Prints the details for the course and coordinator allocated to the course
  225.         for (int i = 0; i < array.size(); i++) {
  226.             System.out.println(array.get(i).getDetails());          //Steps through the array and prints the details
  227.         }
  228.         Admin.menuChoice();
  229.     }
  230.    
  231.  
  232.     public static void ReportTimtable() {
  233.         for (int i = 0; i < array.size(); i++) {
  234.             System.out.println(array.get(i).getTimetabledetails());         //Steps through the array and prints the details
  235.         }
  236.         Coordinator.menuChoice();
  237.     }
  238.     public static void Logout(){    //Logout function to restarts the program by calling the login method
  239.                                     //prompts the user to login again
  240.         loginSystem();
  241.        
  242.     }                      
  243.    
  244.    
  245. //      Scanner user_input = new Scanner(System.in);
  246. //      System.out.print("Are you sure you want to log out?");
  247. //      String a = user_input.nextLine();
  248. //     
  249. //      String secondString = String.format("%-25s %s\n", "To Logout, Press:", "A");
  250. //      String thirdString = String.format("%-25s %s\n", "TO cancel, Press:", "B");
  251. //     
  252. //      switch (a.toLowerCase()) {
  253. //      case "a":
  254. //          seedLogins();
  255. //          break;
  256. //      case "b":
  257. //          Admin.menuChoice();
  258. //          break;
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement