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