Package solution

Class Employee

java.lang.Object
solution.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 Summary

    Constructors
    Constructor
    Description
    Employee(int id, String name, String address, ArrayList<Deduction> deductions)
    Creates a new Employee object with an ID, name, address and list of deductions.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns true if the passed in Object is an Employee and has the same name, address, and id.
    protected String
    formatLine(String type, double value)
    Helper method for formatting the lines in the toString() and paymentBreakdown.
    protected String
    formatLine(String type, String value)
    Helper method for generating the lines in the paystub printout.
    Generates a String that can be written to the paystub which includes information about the Employee, list of Deductions sorted from largest to smallest, and a breakdown of the amount to be paid.
    int
     
    abstract double
    Returns the gross pay for this Employee.
    protected abstract String
    Generates a String that can be added to the end of the paystub to show the breakdown of the payment which includes the gross and net pay, employee type, and any other relevant information like number of hours and rate for Hourly employees or salary for FullTime employees.
    Returns a String that displays the Employee information which include the ID, name, and address.
    protected double
    Returns the total sum of the deductions.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Employee

      public Employee(int id, String name, String address, ArrayList<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 - ArrayList 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()
    • 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 which includes information about the Employee, list of Deductions sorted from largest to smallest, and a breakdown of the amount to be paid.
      Returns:
      String of information to be written to the paystub.
    • toString

      public String toString()
      Returns a String that displays the Employee information which include the ID, name, and address. This should be formatted with formatLine.
      Overrides:
      toString in class Object
      Returns:
      String with Employee information.
    • equals

      public boolean equals(Object o)
      Returns true if the passed in Object is an Employee and has the same name, address, and id.
      Overrides:
      equals in class Object
      Parameters:
      o - Object to compare to this
      Returns:
      true if the passed in Object equals this Object based on the criteria stated.
    • 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 the paystub to show the breakdown of the payment which includes the gross and net pay, employee type, and any other relevant information like number of hours and rate for Hourly employees or salary for FullTime employees. The net pay is the gross pay minus the total deductions amount.
      Returns:
      String that breaks down the payment.
    • formatLine

      protected String formatLine(String type, double value)
      Helper method for formatting the lines in the toString() and paymentBreakdown. The type should have a width of 15 and be left aligned. The value should have a width of 20 and 2 decimal points.
      Parameters:
      type - Type of the value.
      value - Value to be formatted.
      Returns:
      Formatted String with the correct spacing and decimal places.
    • formatLine

      protected String formatLine(String type, String value)
      Helper method for generating the lines in the paystub printout. The type should have a width of 15 and be left aligned. The value should have a width of 20.
      Parameters:
      type - Type of the value.
      value - Value to be formatted.
      Returns:
      Formatted String with the correct spacing and decimal places.