Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Payroll System - Phase 2 ***Include javadoc comments for all new methods added to the project.*** Employee class: Modification 1: In the first constructor, make

Payroll System - Phase 2

***Include javadoc comments for all new methods added to the project.***

Employee class:

Modification 1: In the first constructor, make a copy of the paychecks parameter before using it to set the listOfPaychecks instance variable.

Modification 2: In the copy constructor, make a copy of employeeObject.listOfPaychecks before using it to set the listOfPaychecks instance variable.

Modification 3: In the setListOfPaychecks method, make a copy of the paychecks parameter before using it to set the listOfPaychecks instance variable.

Modification 4: In the getListOfPaychecks method, return a copy of the listOfPaychecks instance variable.

Modification 5: Provide an implementation for the equals method such that it compares the value of the firstName and lastName instance variables of the two objects. In other words, two Employee objects are considered equal if they have the same value for the firstName and lastName fields.

The following is the method signature:

image text in transcribed

Modification 6: Make the class implement the Comparable interface.

Modification 7: Provide an implementation for the compareTo method such that it compares the value of the lastName instance variable of the two objects. If the lastName variable of the calling object is greater, it returns a positive number, if its smaller it returns a negative number, and if they both have the same value, the method then compares the firstName. If the firstName variable of the calling object is greater, it returns a positive number, if its smaller, it returns a negative number, else it returns 0.

Notes:

Use the compareTo method of the String class.

The following is the method signature:

image text in transcribed

Modification 8: Add an instance method called addPaycheck that does not return a value and has 1 parameter of type Paycheck. It adds a copy of the Paycheck parameter to the listOfPaychecks instance variable.

The following is the method signature:

image text in transcribed

Code that needs modification

Employee.java

package payrollsystem_phase1;

import java.util.ArrayList;

/** * The Employee class is an abstract class that holds general data about a company's * employee. Classes representing more specific types of employees should inherit * from this class. * * @author Mayelin */ public abstract class Employee { // instance variables private int employeeID; private String firstName; private String lastName; private ArrayList listOfPaychecks = new ArrayList(); /** * This constructor sets the employee's id, name, and the list of * paychecks received. * @param id The employee's identification number. * @param first The employee's first name. * @param last The employee's last name. * @param paychecks The list of paychecks the employee has received so far. */ public Employee(int id, String first, String last, ArrayList paychecks) { employeeID = id; firstName = first; lastName = last; listOfPaychecks = paychecks; } /** * This is a copy constructor. It initializes the fields of the object being * created to the same values as the fields in the object passed as an argument. * @param employeeObj The object being copied. */ public Employee(Employee employeeObj) { if( employeeObj != null ) { employeeID = employeeObj.employeeID; firstName = employeeObj.firstName; lastName = employeeObj.lastName; listOfPaychecks = employeeObj.listOfPaychecks; } } /** * The getEmployeeID method returns the employee's identification number. * @return The employee's id. */ public int getEmployeeID() { return employeeID; } /** * The getFirstName method returns the employee's first name. * @return The employee's first name. */ public String getFirstName() { return firstName; } /** * The getLastName method returns the employee's last name. * @return The employee's last name. */ public String getLastName() { return lastName; } /** * The getListOfPaychecks method returns a list containing all the paychecks * the employee has received. * @return A reference to the employee's list of paychecks. */ public ArrayList getListOfPaychecks() { return listOfPaychecks; } /** * The setEmployeeID method sets the employee's identification number. * @param id The value to store in the employee id field. */ public void setEmployeeID(int id) { employeeID = id; } /** * The setFirstName method sets the employee's first name. * @param first The value to store in the first name field. */ public void setFirstName(String first) { firstName = first; } /** * The setLastName method sets the employee's last name. * @param last The value to store in the last name field. */ public void setLastName(String last) { lastName = last; } /** * The setListOfPaychecks method sets the list of paychecks that the employee * has received. * @param paychecks The value as an ArrayList of Paycheck elements to store * in the list of paychecks field. */ public void setListOfPaychecks(ArrayList paychecks) { listOfPaychecks = paychecks; } /** * The toString method returns a string containing the state of an Employee object. * @return A string containing the employee's information: id, first name, * last name, and list of paychecks received. */ @Override public String toString() { String output = String.format(" %5s %-24s %s %5s %-24s %s %5s %-24s %s %5s %-24s ", "", "Employee ID:", employeeID, "", "First Name:", firstName, "", "Last Name:", lastName, "", "Paychecks Received:"); if( listOfPaychecks == null || listOfPaychecks.isEmpty() ) output += "No paychecks received."; else { for( Paycheck checkElement : listOfPaychecks) output += checkElement.toString(); } return output + " "; }

}

public boolean equals (Object obj) // provide implementation

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions