Advertisement
Guest User

Untitled

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