Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please follow the instructions below: 1. Please add whats listed below to the code that will be provided under this 2. Add a new class

Please follow the instructions below:

1. Please add whats listed below to the code that will be provided under this

2. Add a new class called PayrollSystem_Phase2.

3. Add the main method provided below.

4. Add another method called parseEmployeePaychecks that has two parameters: one of type int and one of type String. The method returns an ArrayList of Paycheck elements.The int parameter represents an employee id, whereas the String parameter represents the list of paychecks the employee has received and which the method converts to an ArrayList of Paycheck elements.

5. You may assume that the String parameter has the following format:

periodBeginDate1:periodEndDate1:grossAmount1:taxAmount1:bonusAmount1# periodBeginDate2:periodEndDate2:grossAmount2:taxAmount2:bonusAmount2#...

6. Im providing you with an algorithm for the method below:

image text in transcribed

image text in transcribed

Below find original code:

Company.java

package payrollsystem_phase1;

import java.util.ArrayList;

/** * The Company class represents a company having multiple departments. * * @author Mayelin */ public class Company { // instance variables private String companyName; private ArrayList listOfDepartments = new ArrayList(); /** * This constructor sets the company's name and list of departments. * @param name Company's name. * @param departments List of departments in the company. */ public Company(String name, ArrayList departments) { companyName = name; listOfDepartments = departments; }

/** * The getCompanyName method returns the company's name. * @return The company's name. */ public String getCompanyName() { return companyName; }

/** * The getDepartmentList method returns the company's list of departments. * @return The company's list of departments as an ArrayList of Department elements. */ public ArrayList getListOfDepartments() { return listOfDepartments; }

/** * The setCompanyName method sets the name for this company. * @param name The value to store in the name field for this company. */ public void setCompanyName(String name) { companyName = name; }

/** * The setDepartmentList method sets the list of departments for this company. * @param departments The value, as an ArrayList of Department elements, to store * in the list of departments field for this company. */ public void setDepartmentList(ArrayList departments) { listOfDepartments = departments; } /** * The toString method returns a string containing the company's data. * @return A String containing the Company's information: name and list of * departments. */ @Override public String toString() { String output = String.format("%-30s %s", "Company Name:", companyName ); if( listOfDepartments == null || listOfDepartments.isEmpty() ) output += "There are no departments in the company."; else { for( Department deptElement : listOfDepartments) output += " " + deptElement; } return output; } }

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Department.java

package payrollsystem_phase1;

import java.util.ArrayList;

/** * The Department class represents a department within a company. Departments have a * list of employees and a manager. * * @author Mayelin */ public class Department { // instance variables private int departmentID; private String departmentName; private Manager departmentManager; private ArrayList listOfEmployees = new ArrayList(); /** * This constructor sets the department's id and name, as well as the list of * employees and manager. * @param id Department's id. * @param name Department's name. * @param manager Department's manager. * @param employees Department's list of employees. */ public Department(int id, String name, Manager manager, ArrayList employees) { departmentID = id; departmentName = name; departmentManager = new Manager(manager); listOfEmployees = employees; } /** * 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 deptObj The object being copied. */ public Department(Department deptObj) { if( deptObj != null ) { departmentID = deptObj.departmentID; departmentName = deptObj.departmentName; departmentManager = deptObj.departmentManager; listOfEmployees = deptObj.listOfEmployees; } } /** * The getDepartmentID method returns the department's id number. * @return The department's id. */ public int getDepartmentID() { return departmentID; } /** * The getDepartmentName method returns the department's name. * @return The department's name. */ public String getDepartmentName() { return departmentName; } /** * The getDepartmentManager method returns the department's manager. * @return The department's manager. */ public Manager getDepartmentManager() { return new Manager(departmentManager); } /** * The getListOfEmployees method returns the department's list of employees. * @return The department's list of employees as an ArrayList of Employee elements. */ public ArrayList getListOfEmployees() { return listOfEmployees; } /** * The setDepartmentID method sets the id for this department. * @param id The value to store in the id field for this department. */ public void setDepartmentID(int id) { departmentID = id; } /** * The setDepartmentName method sets the name for this department. * @param name The value to store in the name field for this department. */ public void setDepartmentName(String name) { departmentName = name; } /** * The setDepartmentManager method sets the manager for this department. * @param deptManager The value to store in the manager field for this department. */ public void setDepartmentManager(Manager deptManager) { departmentManager = new Manager(deptManager); } /** * The setListOfEmployees method sets the list of employees for this department. * @param employees The value, as an ArrayList of Employee elements, to store * in the list of employees field for this department. */ public void setListOfEmployees(ArrayList employees) { listOfEmployees = employees; } /** * The toString method returns a string containing the department's data. * @return A String containing the Department's information: id, name, * manager, and list of employees. */ @Override public String toString() { String output = String.format( " %-30s %s %-30s %s %-30s %s %-30s %s", "Department ID:", departmentID, "Department Name:", departmentName, "Department Manager:", departmentManager, "List of Employees:", ""); for( Employee emp : listOfEmployees ) output += emp + " "; output += "------------------------------------------------------------------ "; return output; } }

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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 + " "; }

}

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Hourly Employee.java

package payrollsystem_phase1;

import java.util.*;

/** * The HourlyEmployee class is a subclass of the Employee class. It represents * employees that get paid by the hour. * * @author Mayelin */ public class HourlyEmployee extends Employee { // instance variables private double hourlyRate; private double periodHours; /** * This constructor sets the hourly employee's id, name, list of paychecks * received, hourly rate, and period hours. * @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. * @param rate The employee's hourly rate. * @param periodHrs The number of hours the employee works during a pay period. */ public HourlyEmployee(int id, String first, String last, ArrayList paychecks, double rate, double periodHrs) { super(id, first, last, paychecks);

hourlyRate = rate; periodHours = periodHrs; } /** * 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 hourlyEmpObj The object being copied. */ public HourlyEmployee(HourlyEmployee hourlyEmpObj) { super(hourlyEmpObj); if( hourlyEmpObj != null ) { hourlyRate = hourlyEmpObj.hourlyRate; periodHours = hourlyEmpObj.periodHours; } } /** * The getHourlyRate method returns the rate that the employee gets paid per hour. * @return The employee's hourly rate. */ public double getHourlyRate() { return hourlyRate; } /** * The getPeriodHours method returns the number of hours the employee works * during a pay period. * @return The employee's period hours. */ public double getPeriodHours() { return periodHours; } /** * The setHourlyRate method sets the rate that the employee gets paid per hour. * @param rate The value to store in the hourly rate field. */ public final void setHourlyRate(double rate) { hourlyRate = rate; } /** * The setPeriodHours method sets the number of hours the employee works * during a pay period. * @param periodHrs The value to store in the period hours field. */ public final void setPeriodHours(double periodHrs) { periodHours = periodHrs; } /** * The toString method returns a string containing the state of an HourlyEmployee object. * @return A string containing the employee's information: id, first name, * last name, list of paychecks received, hourly rate, and period hours. */ @Override public String toString() { return super.toString() + String.format( "%5s %-24s %-20s %5s %-24s %-20s", "", "Hourly Rate:", hourlyRate, "", "Period Hours:", periodHours ); } }

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Manager.java

package payrollsystem_phase1;

import java.util.ArrayList;

/** * The Manager class is a subclass of the SalariedEmployee class. It represents * salaried employees who also manage a department. * * @author Mayelin */ public class Manager extends SalariedEmployee { // instance variable private double bonus; /** * This constructor sets the manager's id, name, list of paychecks received, * annual salary, and weekly bonus. * @param id The manager's identification number. * @param first The manager's first name. * @param last The manager's last name. * @param paychecks The list of paychecks the manager has received so far. * @param salary The manager's annual salary. * @param bonus The manager's weekly bonus. */ public Manager(int id, String first, String last, ArrayList paychecks, double salary, double bonus) { super(id, first, last, paychecks, salary); this.bonus = bonus; } /** * 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 managerObj The object being copied. */ public Manager(Manager managerObj) { super(managerObj); if( managerObj != null ) { bonus = managerObj.bonus; } } /** * The getBonus method returns the bonus that the manager gets every week. * @return The manager's weekly bonus. */ public double getBonus() { return bonus; } /** * The setBonus method sets the bonus amount that the manager gets. * @param bonus The value to store in the bonus field. */ public void setBonus(double bonus) { this.bonus = bonus; } /** * The toString method returns a string containing the state of a Manager * object. * @return A string containing the manager's information: id, first name, * last name, list of paychecks received, annual salary, and weekly bonus. */ @Override public String toString() { return super.toString() + String.format("%5s %-24s %-20s ", "", "Bonus:", bonus ); } }

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Paycheck.java

package payrollsystem_phase1;

/** * The Paycheck class represents a paycheck paid to an employee for a pay period. * * @author Mayelin */ public class Paycheck { // instance variables private int employeeID; private String periodBeginDate; private String periodEndDate; private double grossAmount; private double taxAmount; private double bonusAmount; private double netAmount; /** * The constructor sets the paycheck's employee id, begin and end dates for * the pay period, as well as the gross, tax, bonus and net amounts. * @param empID Identification number of the employee receiving this paycheck. * @param beginDate Begin date for this paycheck's pay period. * @param endDate End date for this paycheck's pay period. * @param grossAmt Gross amount paid in this paycheck. * @param taxAmt Tax amount deducted in this paycheck. * @param bonusAmt Bonus amount paid in this paycheck. * @param netAmt Net amount paid in this paycheck. */ public Paycheck(int empID, String beginDate, String endDate, double grossAmt, double taxAmt, double bonusAmt, double netAmt) { employeeID = empID; periodBeginDate = beginDate; periodEndDate = endDate; grossAmount = grossAmt; taxAmount = taxAmt; bonusAmount = bonusAmt; netAmount = netAmt; }

/** * 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 paycheckObj The object being copied. */ public Paycheck(Paycheck paycheckObj) { if( paycheckObj != null ) { employeeID = paycheckObj.employeeID; periodBeginDate = paycheckObj.periodBeginDate; periodEndDate = paycheckObj.periodEndDate; grossAmount = paycheckObj.grossAmount; taxAmount = paycheckObj.taxAmount; bonusAmount = paycheckObj.bonusAmount; netAmount = paycheckObj.netAmount; } } /** * The getEmployeeID method returns the identification number of the employee * receiving this paycheck. * @return The employee's id. */ public int getEmployeeID() { return employeeID; }

/** * The getPeriodBeginDate method returns the begin date for this paycheck's pay period. * @return The pay period's begin date. */ public String getPeriodBeginDate() { return periodBeginDate; }

/** * The getPeriodEndDate method returns the end date for this paycheck's pay period. * @return The pay period's end date. */ public String getPeriodEndDate() { return periodEndDate; }

/** * The getGrossAmount method returns the gross amount paid in this paycheck. * @return The paycheck's gross amount. */ public double getGrossAmount() { return grossAmount; }

/** * The getTaxAmount method returns the tax amount deducted in this paycheck. * @return The paycheck's tax amount. */ public double getTaxAmount() { return taxAmount; }

/** * The getBonusAmount method returns the bonus amount paid in this paycheck. * @return The paycheck's bonus amount. */ public double getBonusAmount() { return bonusAmount; }

/** * The getNetAmount method returns the net amount that the employee is getting paid in this paycheck. * @return The paycheck's net amount. */ public double getNetAmount() { return netAmount; }

/** * The setEmployeeID method sets the identification number of the employee * receiving this paycheck. * @param empID The value to store in the employee ID field. */ public void setEmployeeID(int empID) { employeeID = empID; }

/** * The setPeriodBeginDate method sets the begin date for this paycheck's pay period. * @param beginDate The value to store in the pay period begin date field for this paycheck. */ public void setPeriodBeginDate(String beginDate) { periodBeginDate = beginDate; }

/** * The setPeriodEndDate method sets the end date for this paycheck's pay period. * @param endDate The value to store in the pay period end date field for this paycheck. */ public void setPeriodEndDate(String endDate) { periodEndDate = endDate; }

/** * The setGrossAmount method sets the gross amount for this paycheck. * @param payAmt The value to store in the gross amount field for this paycheck. */ public void setGrossAmount(double payAmt) { grossAmount = payAmt; }

/** * The setTaxAmount method sets the tax amount for this paycheck. * @param taxAmount The value to store in the tax amount field for this paycheck. */ public void setTaxAmount(double taxAmount) { this.taxAmount = taxAmount; }

/** * The setBonusAmount method sets the bonus amount for this paycheck. * @param bonusAmount The value to store in the bonus amount field for this paycheck. */ public void setBonusAmount(double bonusAmount) { this.bonusAmount = bonusAmount; }

/** * The setNetAmount method sets the net amount for this paycheck. * @param netAmount The value to store in the net amount field for this paycheck. */ public void setNetAmount(double netAmount) { this.netAmount = netAmount; } /** * The toString method returns a string containing the paycheck's data. * @return A String containing the Paycheck's information: employee id, * pay period begin and end dates, as well as gross, tax, bonus, and net amounts. */ @Override public String toString() { String separator = String.format(" %30s %031d", "", 0).replace('0', '-'); return String.format( " %30s %-20s %10s %30s %-20s %10s %30s %-20s %10s " + " %30s %-20s %10s %30s %-20s %10s %30s %-20s %10s " + " %30s %-20s %10s", "", "Employee ID:", employeeID, "", "Period Begin Date:", periodBeginDate, "", "Period End Date:", periodEndDate, "", "Gross Amount:", grossAmount, "", "Tax Amount:", taxAmount, "", "Bonus Amount:", bonusAmount, "", "Net Amount:", netAmount) + separator; }

}

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

PayrollSystem_Phase1.java

package payrollsystem_phase1;

import java.util.*;

public class PayrollSystem_Phase1 { public static void main(String[] args) { // We cannot instantiate the Employee class since it is abstract System.out.println("/*********************************************************************/"); System.out.println("/* Testing the HourlyEmployee class */"); System.out.println("/*********************************************************************/"); // Creating an HourlyEmployee object using the first constructor HourlyEmployee employee_1 = new HourlyEmployee(1, "Janette", "Hernandez", null, 14.75, 30); // Creating an HourlyEmployee object using the copy constructor HourlyEmployee employee_2 = new HourlyEmployee(employee_1); // Calling some of the setter methods in the HourlyEmployee class. employee_2.setEmployeeID(2); employee_2.setFirstName("Marcela"); employee_2.setLastName("Brown"); employee_2.setHourlyRate(25); employee_2.setPeriodHours(40); System.out.println(" Calling some of the getter methods in the HourlyEmployee class..."); System.out.println( String.format("%-30s%s", "Employee ID:", employee_1.getEmployeeID()) ); System.out.println( String.format("%-30s%s", "First Name:", employee_1.getFirstName()) ); System.out.println( String.format("%-30s%s", "Last Name:", employee_1.getLastName()) ); System.out.println( String.format("%-30s%s", "Hourly Rate:", employee_1.getHourlyRate()) ); System.out.println( String.format("%-30s%s", "Period Hours:", employee_1.getPeriodHours()) ); System.out.println("/*********************************************************************/"); System.out.println("/* Testing the Paycheck class */"); System.out.println("/*********************************************************************/"); // create two Paycheck objects and add them to an ArrayList Paycheck janettesPaycheck_1 = new Paycheck(1, "01/01/2018", "01/07/2018", 442.50, 66.38, 0.0, 376.12); Paycheck janettesPaycheck_2 = new Paycheck(janettesPaycheck_1); janettesPaycheck_2.setPeriodBeginDate("01/08/2018"); janettesPaycheck_2.setPeriodEndDate("01/14/2018");

ArrayList janettesPaychecks = new ArrayList(); janettesPaychecks.add(janettesPaycheck_1); janettesPaychecks.add(janettesPaycheck_2); employee_1.setListOfPaychecks(janettesPaychecks); System.out.println(" Displaying the state of the first HourlyEmployee object (the values in its instance variables)..."); System.out.println(employee_1.toString()); System.out.println(" Displaying the state of the second HourlyEmployee object (the values in its instance variables)..."); System.out.println(employee_2); // this calls the toString method implicitly System.out.println(" *********************************************************************"); System.out.println("* Testing the SalariedEmployee class *"); System.out.println("*********************************************************************"); // create one Paycheck object and add it to an ArrayList Paycheck stevensPaycheck = new Paycheck(3, "01/01/2018", "01/07/2018", 865.38, 173.00, 0.0, 692.38); ArrayList stevensPaychecks = new ArrayList(); stevensPaychecks.add(stevensPaycheck); // Creating a SalariedEmployee object SalariedEmployee employee_3 = new SalariedEmployee(3, "Steven", "Estevez", stevensPaychecks, 0.0); // Calling some of the set methods in the SalariedEmployee class. employee_3.setAnnualSalary(45000.0); // Displaying the state of this object System.out.println(employee_3); // Creating another SalariedEmployee object using the copy constructor SalariedEmployee employee_4 = new SalariedEmployee(employee_3); employee_4.setEmployeeID(4); employee_4.setFirstName("Beatrice"); employee_4.setAnnualSalary(48000.0); Paycheck beatricesPaycheck = new Paycheck(4, "01/08/2018", "01/14/2018", 923.08, 184.70, 0.0, 738.38); ArrayList beatricesPaychecks = new ArrayList(); beatricesPaychecks.add(beatricesPaycheck); employee_4.setListOfPaychecks(beatricesPaychecks); // Displaying the state of this object System.out.println(employee_4.toString()); System.out.println(" *********************************************************************"); System.out.println("* Testing the Manager class *"); System.out.println("*********************************************************************"); // create one Paycheck object and add it to an ArrayList Paycheck michaelsPaycheck = new Paycheck(5, "01/15/2018", "01/21/2018", 1288.45, 257.70, 80.0, 1110.75); ArrayList michaelsPaychecks = new ArrayList(); michaelsPaychecks.add(michaelsPaycheck); // Creating a Manager object using the first constructor. Manager manager_1 = new Manager(5, "Michael", "Colt", michaelsPaychecks, 67000, 50); // Calling some of the set methods in the Manager class. manager_1.setLastName("Colton"); manager_1.setBonus(100.0); // Displaying the state of this object (the values in its instance variables. System.out.println(manager_1.toString()); // create one Paycheck object and add it to an ArrayList Paycheck luisasPaycheck = new Paycheck(6, "01/15/2018", "01/21/2018", 1250.0, 250.0, 72.0, 1072.0); ArrayList luisasPaychecks = new ArrayList(); luisasPaychecks.add(luisasPaycheck); // Creating another Manager object using the copy constructor Manager manager_2 = new Manager(manager_1); // Calling some of the set methods in the Manager class. manager_2.setEmployeeID(6); manager_2.setFirstName("Luisa"); manager_2.setLastName("Lopez"); manager_2.setAnnualSalary(65000.0); manager_2.setBonus(90.0); manager_2.setListOfPaychecks(luisasPaychecks); // Displaying the state of this object (the values in its instance variables. System.out.println(manager_2.toString()); System.out.println(" *********************************************************************"); System.out.println("* Testing the Department class *"); System.out.println("*********************************************************************"); // create an ArrayList of Employees ArrayList dept1Employees = new ArrayList(); dept1Employees.add(employee_1); dept1Employees.add(employee_3); // Creating a Department object using the first constructor. Department dept_1 = new Department(1, "Human Resources", manager_1, dept1Employees); // Displaying the state of the first department object. System.out.println(dept_1.toString()); // create another ArrayList of Employees ArrayList dept2Employees = new ArrayList(); dept2Employees.add(employee_2); dept2Employees.add(employee_4); // Creating a Department object using the copy constructor. Department dept_2 = new Department(dept_1); // Calling some of the setter methods in the Department class. dept_2.setDepartmentID(2); dept_2.setDepartmentName("Information Technology"); dept_2.setDepartmentManager(manager_2); dept_2.setListOfEmployees(dept2Employees); // Displaying the state of the second department object (the values in its instance variables. System.out.println(dept_2.toString()); System.out.println(" *********************************************************************"); System.out.println("* Testing the Company class *"); System.out.println("*********************************************************************"); // Creating a Company object. Company company = new Company("", null); // create an ArrayList of Departments ArrayList departments = new ArrayList(); departments.add(dept_1); departments.add(dept_2); // Calling some of the set methods in the Company class. company.setCompanyName("Our Company"); company.setDepartmentList(departments); // Displaying the state of the company object. System.out.println(company.toString()); } }

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

SalariedEmployee.java

package payrollsystem_phase1;

import java.util.ArrayList;

/** * The SalariedEmployee class is a subclass of the Employee class. It represents * employees that get paid an annual salary. * * @author Mayelin */ public class SalariedEmployee extends Employee { // instance variable private double annualSalary; /** * This constructor sets the salaried employee's id, name, date of birth, list of * paychecks received, and annual salary. * @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. * @param salary The employee's annual salary. */ public SalariedEmployee(int id, String first, String last, ArrayList paychecks, double salary) { super(id, first, last, paychecks);

annualSalary = salary; } /** * 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 salariedEmpObj The object being copied. */ public SalariedEmployee(SalariedEmployee salariedEmpObj) { super(salariedEmpObj); if( salariedEmpObj != null ) { annualSalary = salariedEmpObj.annualSalary; } } /** * The getAnnualSalary method returns the salary that the employee gets paid * per year. * @return The employee's annual salary. */ public double getAnnualSalary() { return annualSalary; } /** * The setAnnualSalary method sets the salary that the employee gets paid * per year. * @param salary The value to store in the annual salary field. */ public final void setAnnualSalary(double salary) { annualSalary = salary; } /** * The toString method returns a string containing the state of a SalariedEmployee * object. * @return A string containing the employee's information: id, first name, * last name, list of paychecks received, and annual salary. */ @Override public String toString() { return super.toString() + String.format("%5s %-24s %-20s ", "", "Annual Salary:", annualSalary ); } }

public static ArrayList parseEmployeePaychecks (int empID, String paycheckData) Declare an ArrayList of Paycheck elements and initialize to an empty list. Split the paycheckData parameter on the # to get each paycheck infor- mation 1 3 8, w sh uld have the fllowing f ldBeglnDate : perl dEn_ dDate : grossAmount:taxAmount:bonusAmount Calculate the netAmount to be: grossAmount - taxAmount + bonusA mount Create a Paycheck object using the emplovee id passed in the first pa- rameter and the data parsed from the second parameter. Add the Paycheck object to the ArrayList that this method returns. After the loop, return the ArrayList of Paycheck objects. ormat: per 7 public static void main (String args[]) string paycheckData = "01/22/2018:01/26/2018:2500.50:375.25:50 + "01/29/2018:02/02/2018:2430.50: 370.75:25

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_2

Step: 3

blur-text-image_3

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

How does or how might the key public affect your organization?

Answered: 1 week ago