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.*** Company class: Modification 1: In the constructor, make a

Payroll System - Phase 2

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

Company class:

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

Modification 2: In the setListOfDepartments method, make a copy of the departments parameter before using it to set the listOfDepartments instance variable.

Modification 3: In the getListOfDepartments method, return a copy of the listOfDepartments instance variable.

Modification 4: Write a method called addDepartment, which doesnt return a value and has 1 parameter of type Department. It adds a copy of the dept parameter to the listOfDepartments instance variable.

The following is the method signature:

image text in transcribed

Modification 5: Write a method called addEmployeeToDepartment, which doesnt return a value and has 2 parameters, the first is of type int, and the second of type Employee. This method iterates through all the elements in the listOfDepartments instance variable looking for a Department whose departmentID is equal to the int value passed as the first argument. If it finds it, it adds to it a copy of the Employee object passed as the second argument.

Below is the method header:

image text in transcribed

Modification 6: Write a method called setDepartmentManager, which doesnt return a value and has 2 parameters, the first is of type int, and the second of type Manager. This method iterates through all the elements in the listOfDepartments instance variable looking for a Department whose departmentID is equal to the int value passed as the first argument. If it finds it, it calls the setDepartmentManager method on that object passing the manObject parameter.

image text in transcribed

Code that needs to be Modified:

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 setListOfDepartments(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; } }

public void addDepartment (Department dept) // 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

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions