Package solution
Class Employee
java.lang.Object
solution.Employee
Base abstract class for an Employee that contains an id, name, and address
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
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
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.toString()
Returns a String that displays the Employee information which include the ID, name, and address.
-
Constructor Details
-
Employee
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
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
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 that has the same name, address, and id. -
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
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
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.
-