Advertisement
Guest User

Untitled

a guest
May 13th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.47 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.  
  6. // USER LOGINS IN TEXT FILE "UserAccounts"
  7. public class HRApplication {
  8.  
  9. // Text file that contains the logins for accounts
  10. public static final String AccountFile = "UserAccounts";
  11. public static final String staffLising = "casualStaffListing";
  12. // Array that hold the details for accounts
  13. private static ArrayList<Staff> accounts = new ArrayList<Staff>();
  14. // Array that holds course details
  15. private static ArrayList<Course> array = new ArrayList<Course>();
  16. private static ArrayList<CasualStaff> Listing = new ArrayList<CasualStaff>();
  17.  
  18. public static void main(String[] args) {
  19. try {
  20. UserAccounts();
  21. } catch (FileNotFoundException e) {
  22. // TODO Auto-generated catch block
  23. e.printStackTrace();
  24. }
  25. }
  26.  
  27. // This method Reads the username and passwords for each user from textfile
  28. // "UserAccount"
  29. public static void UserAccounts() throws FileNotFoundException {
  30. // Creats objects and adds to array list.
  31. Scanner input = new Scanner(new File(AccountFile));
  32.  
  33. while (input.hasNextLine()) { // Loops as long as there is another line
  34.  
  35. String line = input.nextLine();
  36. // Checks if the data is for Admin, creats admin object
  37. if (line.equals("ADMIN")) {
  38. String AdminUsername = input.nextLine();
  39. String AdminPassword = input.nextLine();
  40.  
  41. Admin admin = new Admin(AdminUsername, AdminPassword);
  42. accounts.add(admin);
  43.  
  44. }
  45. if (line.equals("COORDINATOR")) {
  46. String coordinatorUsername = input.nextLine();
  47. String coordinatorPassword = input.nextLine();
  48. String coordinatorName = input.nextLine();
  49. String coordinatorSubject = input.nextLine();
  50. String coordinatorSubjectID = input.nextLine();
  51.  
  52. Coordinator coordinator = new Coordinator(coordinatorUsername, coordinatorPassword, coordinatorName,
  53. coordinatorSubject, coordinatorSubjectID);
  54. accounts.add(coordinator);
  55.  
  56. }
  57. if (line.equals("APPROVER")) {
  58. String approverUsername = input.nextLine();
  59. String approverPassword = input.nextLine();
  60.  
  61. Approver approver = new Approver(approverUsername, approverPassword);
  62. accounts.add(approver);
  63.  
  64. }
  65.  
  66. }
  67. casualStaffListing();
  68. }
  69.  
  70. public static void casualStaffListing() throws FileNotFoundException {
  71. Scanner input = new Scanner(new File(staffLising));
  72.  
  73. while (input.hasNextLine()) {
  74.  
  75. String line = input.nextLine();
  76. if (line.equals("Casual")) {
  77. String staffID = input.nextLine();
  78. String staffName = input.nextLine();
  79. boolean staffMonday = input.nextBoolean();
  80. boolean staffTuesday = input.nextBoolean();
  81. boolean staffWednesday = input.nextBoolean();
  82. boolean staffThursday = input.nextBoolean();
  83. boolean staffFriday = input.nextBoolean();
  84. String staffSubjectID = input.next();
  85.  
  86. CasualStaff staffListing = new CasualStaff(staffID, staffName, staffMonday, staffTuesday,
  87. staffWednesday, staffThursday, staffFriday, staffSubjectID);
  88. Listing.add(staffListing);
  89.  
  90. }
  91.  
  92. }
  93. loginSystem();
  94. }
  95.  
  96. // Adds the login details of the users into the system
  97. // public static void seedLogins() {
  98. // // Since there's only one user for each of these staff members, the log
  99. // // in details are stored in an array
  100. // Admin admin = new Admin("Admin", "cat");
  101. // Approver approver = new Approver("Approver", "dog");
  102. // Coordinator coordinator = new Coordinator("Coordinator", "mouse");
  103. // accounts.add(admin);
  104. // accounts.add(approver);
  105. // accounts.add(coordinator);
  106. // loginSystem();
  107. // }
  108.  
  109. // This is the Login driver method, It prompts the users to enter their
  110. // username and passwords
  111. public static void loginSystem() {
  112. boolean idExist = false;
  113. Scanner input = new Scanner(System.in);
  114. System.out.printf("%-15s %s", "Please enter Username:", "");
  115. String usernameInput = input.nextLine();
  116. System.out.printf("%-15s %s", "Please enter Password:", "");
  117. String passwordInput = input.nextLine();
  118.  
  119. // Loops through the array list to match the username and password
  120. for (int i = 0; i < accounts.size(); i++) {
  121.  
  122. if (usernameInput.equals(accounts.get(i).getUsername())) {
  123. if (passwordInput.equals(accounts.get(i).getPassword())) {
  124. idExist = true;
  125.  
  126. // Checks if the account details are for which user
  127. if (accounts.get(i) instanceof Admin) {
  128. Admin.menuChoice();
  129. } else if (accounts.get(i) instanceof Approver) {
  130. Approver.menuChoice();
  131. } else if (accounts.get(i) instanceof Coordinator) {
  132. Coordinator.menuChoice();
  133.  
  134. }
  135. }
  136. }
  137. }
  138.  
  139. // If account details dont exist, prompts user to try again
  140. System.out.println("Username or password is incorrect, please try again");
  141. loginSystem(); // Restarts the method
  142. input.close();
  143. }
  144.  
  145. // Method for the addCourse option in the admin menu
  146. public static void addCourse() {
  147.  
  148. Scanner user_input = new Scanner(System.in);
  149.  
  150. // input course name
  151. System.out.printf("%-35s %s", "Enter Course Name:", "");
  152. String Coursename = user_input.nextLine();
  153.  
  154. // input vehicle Height checks if its numeric
  155. System.out.printf("%-35s %s", "Please Course ID:", "");
  156. String CourseID = user_input.nextLine();
  157.  
  158. System.out.printf("%-35s %s", "Enter pay rates per hour:", "");
  159. int Coursepay = user_input.nextInt();
  160.  
  161. // Creats object for the course and adds to course array
  162. Course newCourse = new Course(Coursename, CourseID, Coursepay);
  163. array.add(newCourse);
  164.  
  165. System.out.printf("New Course created successfully for %s !%n", Coursename);
  166.  
  167. Admin.menuChoice();
  168. user_input.close();
  169. }
  170.  
  171. // Method for the Alloction option in the admin menu
  172. public static void addCoordinator() {
  173. Scanner user_input = new Scanner(System.in);
  174.  
  175. String cID = null;
  176. String Course_name = null;
  177. int Course_pay = 0;
  178.  
  179. System.out.printf("%-35s %s", "Enter course ID:", "");
  180. cID = user_input.nextLine();
  181.  
  182. // Checking if registration id already exist
  183. boolean cIDExists = false;
  184. for (Course g : array) {
  185. if ((cID.equals(g.getCourse_ID()))) {
  186. cIDExists = true;
  187. Course_name = g.getCourse_ID();
  188. Course_pay = g.getCourse_pay();
  189.  
  190. }
  191. }
  192.  
  193. if (cIDExists) {
  194. System.out.printf("%-35s %s", "Enter coordinator ID:", "");
  195. String CoordID = user_input.nextLine();
  196.  
  197. for (int i = 0; i < accounts.size(); i++) {
  198. if (CoordID.equals((accounts.get(i)).getUsername())) {
  199. if (accounts.get(i) instanceof Coordinator) {
  200. // Makes object of the allocation and adds to array
  201. AllocateCoordinator newCoord = new AllocateCoordinator(Course_name, cID, Course_pay, CoordID);
  202.  
  203. array.add(newCoord);
  204.  
  205. System.out.printf("Successfully allocated for %s !%n", cID);
  206.  
  207. Admin.menuChoice();
  208. user_input.close();
  209.  
  210. } else {
  211. System.out.println("This ID does not belong to a coordinator");
  212. Admin.menuChoice();
  213. }
  214.  
  215. }
  216.  
  217. }
  218. System.out.println("ID does not exist");
  219. Admin.menuChoice();
  220. }
  221. }
  222.  
  223. public static void allocateCasualStaff() {
  224. Scanner user_input = new Scanner(System.in);
  225. String courseDay = null;
  226. String cID = null;
  227. String Course_name = null;
  228. int Course_pay = 0;
  229. String staffID = null;
  230. boolean allocate = false;
  231. boolean staffExists = false;
  232.  
  233. System.out.printf("%-35s %s", "Enter course ID:", "");
  234. cID = user_input.nextLine();
  235.  
  236. // Checking if registration id already exist
  237.  
  238. for (int i = 0; i < array.size(); i++) {
  239. if (cID.equals(array.get(i).getCourse_ID())) {
  240. Course_name = array.get(i).getCourse_ID();
  241. Course_pay = array.get(i).getCourse_pay();
  242.  
  243. } else {
  244. System.out.println("Course ID does not exist");
  245. Coordinator.menuChoice();
  246. }
  247.  
  248. System.out.println("Staff applications for this course");
  249. for (int a = 0; a < Listing.size(); a++) {
  250. if (cID.equals(Listing.get(a).getSubjectID()))
  251. System.out.println(Listing.get(a).getStaffDetails());
  252. }
  253. System.out.println("Please select which staff to allocate");
  254. staffID = user_input.nextLine();
  255. for (int c = 0; c < Listing.size(); c++) {
  256. if (staffID.equals(Listing.get(i).getID())) {
  257. staffExists = true;
  258. }
  259. }
  260. if (staffExists) {
  261. System.out.println("which day?");
  262. courseDay = user_input.nextLine();
  263. AllocateCasualStaff newStaff = new AllocateCasualStaff(Course_name, cID, Course_pay, staffID, courseDay,
  264. allocate);
  265.  
  266. array.add(newStaff);
  267.  
  268. System.out.printf("Successfully allocated for %s !%n", staffID);
  269.  
  270. Admin.menuChoice();
  271. user_input.close();
  272.  
  273.  
  274. }
  275.  
  276. }
  277.  
  278.  
  279. }
  280.  
  281. public static void createTimetable() {
  282. Scanner user_input = new Scanner(System.in);
  283.  
  284. String cID = null;
  285. String Course_name = null;
  286. int Course_pay = 0;
  287. String Coord_name = null;
  288.  
  289. System.out.printf("%-35s %s", "Enter course ID:", "");
  290. cID = user_input.nextLine();
  291.  
  292. // Checking if registration id already exist
  293. boolean cIDExists = false;
  294. for (Course g : array) {
  295. if ((cID.equals(g.getCourse_ID()))) {
  296. cIDExists = true;
  297. Course_name = g.getCourse_name();
  298. Course_pay = g.getCourse_pay();
  299. Coord_name = g.Coord_name();
  300. }
  301. }
  302.  
  303. if (cIDExists) {
  304. String mondayTime = null;
  305. String tuesdayTime = null;
  306. String wednesdayTime = null;
  307. String thursdayTime = null;
  308. String fridayTime = null;
  309.  
  310. System.out.println("Select true or false if the course is on this day");
  311. System.out.printf("%-35s %s", "Monday:", "");
  312. boolean mondayCourse = user_input.nextBoolean();
  313. if (mondayCourse) {
  314. System.out.printf("%-35s %s", "Course start Time:", "");
  315. String a = user_input.nextLine();
  316. mondayTime = user_input.nextLine();
  317. }
  318.  
  319. System.out.printf("%-35s %s", "Tuesday:", "");
  320. boolean tuesdayCourse = user_input.nextBoolean();
  321. if (tuesdayCourse) {
  322. System.out.printf("%-35s %s", "Course start Time:", "");
  323. String a = user_input.nextLine();
  324. tuesdayTime = user_input.nextLine();
  325. }
  326.  
  327. System.out.printf("%-35s %s", "Wednesday:", "");
  328. boolean wednesdayCourse = user_input.nextBoolean();
  329. if (wednesdayCourse) {
  330. System.out.printf("%-35s %s", "Course start Time:", "");
  331. String a = user_input.nextLine();
  332. wednesdayTime = user_input.nextLine();
  333. }
  334.  
  335. System.out.printf("%-35s %s", "Thursday:", "");
  336. boolean thursdayCourse = user_input.nextBoolean();
  337. if (thursdayCourse) {
  338. System.out.printf("%-35s %s", "Course start Time:", "");
  339. String a = user_input.nextLine();
  340. thursdayTime = user_input.nextLine();
  341. }
  342.  
  343. System.out.printf("%-35s %s", "Friday:", "");
  344. boolean fridayCourse = user_input.nextBoolean();
  345. if (fridayCourse) {
  346. System.out.printf("%-35s %s", "Course start Time:", "");
  347. String a = user_input.nextLine();
  348. fridayTime = user_input.nextLine();
  349. }
  350.  
  351. createTimetable newTimetable = new createTimetable(Course_name, cID, Course_pay, Coord_name, mondayCourse,
  352. mondayTime, tuesdayCourse, tuesdayTime, wednesdayCourse, wednesdayTime, thursdayCourse,
  353. thursdayTime, fridayCourse, fridayTime); // Makes object of
  354. // the
  355. // allocation
  356. // and adds to
  357. // array
  358. array.add(newTimetable);
  359.  
  360. System.out.printf("Successfully allocated time for %s !%n", cID);
  361.  
  362. Coordinator.menuChoice();
  363. user_input.close();
  364.  
  365. } else {
  366.  
  367. System.out.println("no course ID found.");
  368. Coordinator.menuChoice();
  369.  
  370. }
  371. }
  372.  
  373. // Method for the report function in the admin menu Prints the details for
  374. // the course and coordinator allocated to the course
  375. public static void Report() {
  376. for (int i = 0; i < array.size(); i++) {
  377. // Steps through the array and prints the details
  378. System.out.println(array.get(i).getDetails());
  379. }
  380. Admin.menuChoice();
  381. }
  382.  
  383. public static void ReportApproval() {
  384. for (int i = 0; i < array.size(); i++) {
  385. // Steps through the array and prints the details
  386. System.out.println(array.get(i).getDetails());
  387. }
  388. Approver.menuChoice();
  389. }
  390. public static void ReportCoordinator() {
  391. for (int i = 0; i < array.size(); i++) {
  392. // Steps through the array and prints the details
  393. System.out.println(array.get(i).getDetails());
  394. }
  395. Coordinator.menuChoice();
  396. }
  397.  
  398.  
  399. public static void ReportTimtable() {
  400. for (int i = 0; i < array.size(); i++) {
  401. // Steps through the array and prints the details
  402. System.out.println(array.get(i).getTimetabledetails());
  403. }
  404. Coordinator.menuChoice();
  405. }
  406.  
  407. public static void ReportTimtableApprover() {
  408. for (int i = 0; i < array.size(); i++) {
  409. // Steps through the array and prints the details
  410. System.out.println(array.get(i).getTimetabledetails());
  411. }
  412. Approver.menuChoice();
  413. }
  414.  
  415.  
  416. public static void ReportTimtableAdmin() {
  417. for (int i = 0; i < array.size(); i++) {
  418. // Steps through the array and prints the details
  419. System.out.println(array.get(i).getTimetabledetails());
  420. }
  421. Admin.menuChoice();
  422. }
  423.  
  424. // Logout function to restarts the program by calling the login method
  425. // prompts the user to login again
  426. public static void Logout() {
  427. loginSystem();
  428.  
  429. }
  430.  
  431. public static void CheckApproval() {
  432. // TODO Auto-generated method stub
  433.  
  434. Scanner user_input = new Scanner(System.in);
  435.  
  436. String cID = null;
  437. String Course_name = null;
  438. int Course_pay = 0;
  439. boolean Approve = false;
  440.  
  441. System.out.printf("%-35s %s", "Enter course ID:", "");
  442. cID = user_input.nextLine();
  443.  
  444. // Checking if registration id already exist
  445. boolean cIDExists = false;
  446. for (Course g : array) {
  447. if ((cID.equals(g.getCourse_ID()))) {
  448. cIDExists = true;
  449. Course_name = g.getCourse_ID();
  450. Course_pay = g.getCourse_pay();
  451.  
  452. }
  453. }
  454.  
  455. if (cIDExists) {
  456.  
  457. System.out.printf("%-35s %s", "Approving course (true/false):", "");
  458. Approve = user_input.nextBoolean();
  459.  
  460. ApprovingCourse newApproval = new ApprovingCourse(Course_name, cID, Course_pay, Approve);
  461.  
  462. array.add(newApproval);
  463.  
  464. System.out.printf("Successfully allocated for %s !%n", cID);
  465.  
  466. Approver.menuChoice();
  467. user_input.close();
  468.  
  469. } else {
  470. System.out.println("This ID does not belong to a coordinator");
  471. Approver.menuChoice();
  472. }
  473.  
  474.  
  475.  
  476. }
  477.  
  478. }
  479.  
  480.  
  481. // public static void allocateCasualStaff() {
  482. // Scanner user_input = new Scanner(System.in);cc
  483. //
  484. // String cID = null;
  485. //
  486. // System.out.printf("%-35s %s", "Enter course ID:", "");
  487. // cID = user_input.nextLine();
  488. //
  489. // // Checking if registration id already exist
  490. // boolean cIDExists = false;
  491. // for (Course g : array) {
  492. // if ((cID.equals(g.getCourse_ID()))) {
  493. // cIDExists = true;
  494. // }
  495. // }
  496. //
  497. // if (cIDExists) {
  498. // System.out.printf("%-35s %s", "Enter coordinator name:", "");
  499. // String Coord_name = user_input.nextLine();
  500. // // Makes object of the allocation and adds to array
  501. // array.add(newCoord);
  502. // AllocateCoordinator newCoord = new AllocateCoordinator(Course_name,
  503. // Course_ID, Course_pay, Coord_name);
  504. //
  505. // System.out.printf("Successfully allocated for %s !%n", Course_ID);
  506. //
  507. // Admin.menuChoice();
  508. // user_input.close();
  509. //
  510. // } else {
  511. // System.out.println("no course ID found.");
  512. // Admin.menuChoice();
  513. // }
  514. //
  515. // }
  516. //
  517. // }
  518.  
  519. // Scanner user_input = new Scanner(System.in);
  520. // System.out.print("Are you sure you want to log out?");
  521. // String a = user_input.nextLine();
  522. //
  523. // String secondString = String.format("%-25s %s\n", "To Logout, Press:", "A");
  524. // String thirdString = String.format("%-25s %s\n", "TO cancel, Press:", "B");
  525. //
  526. // switch (a.toLowerCase()) {
  527. // case "a":
  528. // seedLogins();
  529. // break;
  530. // case "b":
  531. // Admin.menuChoice();
  532. // break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement