Guest User

Untitled

a guest
Aug 16th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. /*
  2. A program that accepts a list of company employees from a file and perform search, sort operaions on them
  3. */
  4. import java.util.Date;
  5. import java.text.SimpleDateFormat;
  6. import java.lang.Comparable;
  7. import java.io.File;
  8. import java.util.Scanner;
  9. import java.io.FileReader;
  10. import java.io.FileWriter;
  11. import java.io.IOException;
  12. import java.text.ParseException;
  13. import java.io.FileNotFoundException;
  14.  
  15. public class Employee{
  16. public static void employeeList(){
  17. System.out.println("\t\t\t\t\t\t\tList of the Employees in EPIUSE\n\nThis program reads the list of EPIUSE employees from a file and allows user to perform search and sort operations on it");
  18. }
  19. public static void fileTitle(){
  20. System.out.println("\t\t\t\t\t\t\tEmployee List\n\nFirstName \t\tSurname \t\tBirthDate \t\tEmployee Number \t\tRole Designation \t\tSalary \t\tReporting Structure");
  21. System.out.println("----------\t\t----------\t\t----------\t\t---------\t\t----------\t\t----------\t\t----------\t\t----------");
  22. }
  23. public static void printFileInfo(String firstName, String surName, Date birthDate, Integer employerNo, String roleDesignation, Double salary, String reportingStructure, SimpleDateFormat sdf){
  24. System.out.printf("%20s%20.2f%20.2f%20.2f%20.2f%20.2f OT\n", firstName, surName, sdf.format(birthDate), employerNo, roleDesignation, salary, reportingStructure);
  25.  
  26. }
  27.  
  28.  
  29. public static void main (String[] args) throws FileNotFoundException {
  30. SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
  31. sdf.setLenient(false);
  32. Date birthDate;
  33.  
  34.  
  35. String firstName, surName, roleDesignation, reportingStructure;
  36.  
  37. Double salary;
  38. int employerNo;
  39.  
  40. employeeList();
  41. fileTitle();
  42.  
  43. File file = new File("./employee_list.txt");
  44. Scanner sc = new Scanner(file);
  45. sc.nextLine();
  46. while (sc.hasNextLine()){
  47. firstName = sc.next();
  48. surName = sc.next();
  49. try {
  50. birthDate = sdf.parse(sc.next());
  51. } catch (ParseException e){
  52. e.printStackTrace();
  53. birthDate = new Date();
  54. }
  55. employerNo = sc.nextInt();
  56. roleDesignation = sc.next();
  57. salary = sc.nextDouble();
  58. reportingStructure = sc.next();
  59. printFileInfo(firstName, surName, birthDate, employerNo, roleDesignation, salary, reportingStructure, sdf);
  60. sc.close();
  61. }
  62.  
  63.  
  64. }
  65. }
Add Comment
Please, Sign In to add comment