Skip to content

3 Departments and association

  1. If needed, retrieve the OOP Company project up to chapter 2 from DLO. It contains the Program and Person classes as you left them at the end of chapter 2.

  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.

    Mermaid diagram Mermaid diagram

  3. Add a Department class to the Models folder.

    a) The default values for name and location are both "Unknown";
    b) Apply constructor chaining.
    c) Create properties for the two attributes.

  4. Modify the Person class:

    a) Add the department attribute of type Department.
    b) Adjust the relevant constructors. Use the default values of the Department class.
    c) Create a property for the department attribute.

  5. In your Main method:

    a) Remove or comment out any existing code.
    b) Create an array named departments with 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 named boss (name: Mark, city: Den Haag, monthly salary: 10000, department: Management). Note: use the array you just created for the department.
    d) Create a person named employee (name: Caroline, city: Delft, monthly salary: 4000, department: Support);
    e) Create a person named assistant (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