Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Modification 10: Write a method called addEmployee , which doesnt return a value and has 1 parameter of type Employee . It adds a

Java

Modification 10: Write a method called addEmployee, which doesnt return a value and has 1 parameter of type Employee. It adds a copy of the Employee parameter to the listOfEmployees instance variable.

Note:

You need to use the instanceof operator to cast the parameter into either HourlyEmployee or SalariedEmployee; very similar to how its done in the constructors except that youll be working with only one Employee object as opposed to an ArrayList.

The following is the method signature:

public void addEmployee(Employee employee)

{

// provide implementation

}

*****************code********************

public class Department { private int departmentID; private String departmentName; private Manager departmentManager; private ArrayList listOfEmployees; public Department(int iD, String name, Manager manager, ArrayList list){ departmentID = iD; departmentName = name; departmentManager = manager; listOfEmployees = list; } public Department (Department dObject) { if (dObject != null) { departmentID = dObject.departmentID; departmentName = dObject.departmentName; departmentManager = dObject.departmentManager; listOfEmployees = dObject.listOfEmployees; } } public void setDepartmentID(int iD){ this.departmentID = iD; } public int getDepartmentID(){ return this.departmentID; } public void setDepartmentName(String name){ this.departmentName = name; } public String getDepartmentName(){ return this.departmentName; } public void setDepartmentManager(Manager manager){ this.departmentManager = manager; } public Manager getDepartmentManager(){ return this.departmentManager; } public void setListOfEmployees(ArrayList list){ this.listOfEmployees = list; } public ArrayList getListOfEmployees(){ return this.listOfEmployees; } /** * * * Creates a string and outputs the information needed using concatenation. */ @Override public String toString() { String output = "Department ID: " + departmentID + " " + "Department Name: " + departmentName + " " + "Department Manager: " + departmentManager + " " + "List of Employees: " + " "; if( listOfEmployees == null || listOfEmployees.isEmpty() ) output += "No paychecks received."; else { for( Employee checkElement : listOfEmployees) output += checkElement.toString(); } return output + " "; } }

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

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

Students also viewed these Databases questions

Question

b. What groups were most represented? Why do you think this is so?

Answered: 1 week ago