3 Departments and association
-
If needed, retrieve the OOP Company project up to chapter 2 from DLO. It contains the
ProgramandPersonclasses as you left them at the end of chapter 2. -
In this assignment you will extend the company according to the following class diagram. A department can contain 0 or more persons. A person belongs to 1 department. A person knows which department they are in; a department does not know about its persons.
-
Add a
Departmentclass to theModelsfolder.a) The default values for
nameandlocationare both "Unknown";
b) Apply constructor chaining.
c) Create properties for the two attributes. -
Modify the
Personclass:a) Add the
departmentattribute of typeDepartment.
b) Adjust the relevant constructors. Use the default values of theDepartmentclass.
c) Create a property for thedepartmentattribute. -
In your
Mainmethod:a) Remove or comment out any existing code.
b) Create an array nameddepartmentswith 4 departments:
i) The department Operations in Hilversum;
ii) The department Support in Amsterdam;
iii) The department Management in Almere;
iv) The department Documentation in Gouda.
c) Create a person namedboss(name: Mark, city: Den Haag, monthly salary: 10000, department: Management). Note: use the array you just created for the department.
d) Create a person namedemployee(name: Caroline, city: Delft, monthly salary: 4000, department: Support);
e) Create a person namedassistant(name: Klaas, other values are defaults);
f) Add code so that your output looks like this (the italic values in the output should come from the relevant objects):1 2 3 4
The number of people in the company is 3 Mark works in Almere and lives in Den Haag Caroline works in department Support and earns 4000,00 Klaas works in department Unknown and lives in Unknown