Package username

Class Employee

java.lang.Object
username.Employee
Direct Known Subclasses:
FullTime, Hourly

public abstract class Employee extends Object
Base abstract class for an Employee that contains an id, name, address, and list of deductions.
  • Constructor Details

    • Employee

      public Employee(int id, String name, String address, List<Deduction> deductions) throws IllegalArgumentException
      Creates a new Employee object with an ID, name, address and list of deductions.
      Parameters:
      id - ID of the employee
      name - Name of employee
      address - Address of the employee
      deductions - List of Deductions for the Employee
      Throws:
      IllegalArgumentException - If id is less than or equal to zero, or name, address, or deductions are null.
  • Method Details

    • getId

      public int getId()
    • getName

      public String getName()
    • getAddress

      public String getAddress()
    • getPay

      public abstract double getPay()
      Returns the gross pay for this Employee
      Returns:
      Gross pay.
    • generatePayStub

      public String generatePayStub()
      Generates a String that can be written to the paystub.
      Returns:
      String of information to be written to the paystub which include information about the Employee, list of Deductions sorted from largest to smallest, and a breakdown of the amount to be paid.
    • toString

      public String toString()
      Returns a String representation of the Employee.
      Overrides:
      toString in class Object
      Returns:
      String with the ID, name, and address of the Employee.
    • totalDeductions

      protected double totalDeductions()
      Returns the total sum of the deductions.
      Returns:
      Total sum of deductions.
    • paymentBreakdown

      protected abstract String paymentBreakdown()
      Generates a String that can be added to the end of paystub String to show the breakdown of the payment.
      Returns:
      String that includes the gross and net pay of the employee, the employee type, and any other relevant information like number of hours for Hourly employees. The net pay is the gross pay for the pay period minus the total deductions amount.
    • formatLine

      public static String formatLine(String type, double value)
      Generates a String that consists of a String and number with the correct formating.
      Parameters:
      type - Type of the value.
      value - Value to be formatted.
      Returns:
      Formatted String with the correct spacing and decimal places.