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, and address
  • Constructor Summary

    Constructors
    Constructor
    Description
    Employee(int id, String name, String address)
    Creates a new Employee object with an ID, name, and address
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns true if the passed in Object is an Employee that has the same name, address, and id.
    protected static String
    formatLine(String type, double value)
    Helper method for formatting the lines in the toString() and paymentBreakdown.
    protected static String
    formatLine(String type, String value)
    Helper method for formatting the lines in the toString() and paymentBreakdown.
    Generates a String that can be written to the paystub.
    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.
    Returns a String that displays the Employee information which include the ID, name, and address.

    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) throws IllegalArgumentException
      Creates a new Employee object with an ID, name, and address
      Parameters:
      id - ID of the employee.
      name - Name of employee.
      address - Address of the employee.
      Throws:
      IllegalArgumentException - If ID is less than or equal to zero, or name or address are null.
  • Method Details

    • 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. This String includes information about the Employee 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 that 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 obj equals this based on the criteria stated.
    • 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. This should be formatted with formatLine.
      Returns:
      String that breaks down the payment.
    • formatLine

      protected static 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 places.
      Parameters:
      type - Type of the value.
      value - Value to be formatted.
      Returns:
      Formatted String with the correct spacing and decimal places.
    • formatLine

      protected static String formatLine(String type, String 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.
      Parameters:
      type - Type of the value.
      value - Value to be formatted.
      Returns:
      Formatted String with the correct spacing and decimal places.