I try to implement an specification diagram. There are 3 classes: Company, Department, Employee.
- Employee has name, salary, department.
- Every Department has a Company, name, employees (0..n) - I made a LinkedList for that -, and a Manager of the Employee Type which can be manager in only one department.
Departments can have subdepartments of the Department Type - I made a LinkedList for that, too. And a "different" constructor for subdepartments.
Every Company has a name.
Now I have a questions and an issue:
- QUESTION: Since a manager can be manager in only one department, I check in
setManagerif any department has this manager as manager. If so, then I return. Is this a correct way to do this? I thought about a booleanisManagerbut there's nothing like that in the specification. - ISSUE: If I remove an Employee from a departments list with
removeEmployeeI set the Department variable of the Employee in the same method to null. But if I try to get the name of the Department in which the Employee is, I still get the Department and not null.
That's how the removeEmployee of the Department class code looks like:
public void removeEmployee(Employee e) {
employees.remove(e);
e.setDepartment(null);
}
In the main method I do this to check if the Department of the Employee is null:
departmentName.employees.remove(employeeName);
System.out.println(employeeName.getDepartment().getName());
The Output should be null, but I get departmentName. He's removed from the employees list of the Department but to set the Department of the Employee to null fails.
I would be happy if you could answer my question and help me with my issue.
I could also upload the diagram and my three classes to let you check but I don't think you want to waste your time.
Kind regards, Newb
Employee? It's hard to answer without seeing the full details. - MureinikdepartmentName.employees.remove(employeeName);- You aren't really callingremoveEmployeehere. - BackSlash