Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- A program that accepts a list of company employees from a file and perform search, sort operaions on them
- */
- import java.util.Date;
- import java.text.SimpleDateFormat;
- import java.lang.Comparable;
- import java.io.File;
- import java.util.Scanner;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.text.ParseException;
- import java.io.FileNotFoundException;
- public class Employee{
- public static void employeeList(){
- 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");
- }
- public static void fileTitle(){
- 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");
- System.out.println("----------\t\t----------\t\t----------\t\t---------\t\t----------\t\t----------\t\t----------\t\t----------");
- }
- public static void printFileInfo(String firstName, String surName, Date birthDate, Integer employerNo, String roleDesignation, Double salary, String reportingStructure, SimpleDateFormat sdf){
- 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);
- }
- public static void main (String[] args) throws FileNotFoundException {
- SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
- sdf.setLenient(false);
- Date birthDate;
- String firstName, surName, roleDesignation, reportingStructure;
- Double salary;
- int employerNo;
- employeeList();
- fileTitle();
- File file = new File("./employee_list.txt");
- Scanner sc = new Scanner(file);
- sc.nextLine();
- while (sc.hasNextLine()){
- firstName = sc.next();
- surName = sc.next();
- try {
- birthDate = sdf.parse(sc.next());
- } catch (ParseException e){
- e.printStackTrace();
- birthDate = new Date();
- }
- employerNo = sc.nextInt();
- roleDesignation = sc.next();
- salary = sc.nextDouble();
- reportingStructure = sc.next();
- printFileInfo(firstName, surName, birthDate, employerNo, roleDesignation, salary, reportingStructure, sdf);
- sc.close();
- }
- }
- }
Add Comment
Please, Sign In to add comment