Package solution
Class Employee
java.lang.Object
solution.Employee
Base abstract class for an Employee that contains an id,
name, address, and list of deductions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
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
getId()
abstract double
getPay()
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.toString()
Returns a String that displays the Employee information which include the ID, name, and address.protected double
Returns the total sum of the deductions.
-
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
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
Returns a String that displays the Employee information which include the ID, name, and address. This should be formatted with formatLine. -
equals
Returns true if the passed in Object is an Employee and has the same name, address, and id. -
totalDeductions
protected double totalDeductions()Returns the total sum of the deductions.- Returns:
- Total sum of deductions.
-
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
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
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.
-