Skip to content

5 Abstract Person and polymorphism

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

  2. Make the Person class and the CalculateYearlyIncome() method abstract according to the class diagram.

    Mermaid diagram Mermaid diagram

  3. Adjust your Main method as follows:

    1. Create an array named departments with four departments:
      1. The department Operations in Hilversum;
      2. The department Support in Amsterdam;
      3. The department Management in Almere;
      4. The department Documentation in Gouda.
    2. Create four persons:
      1. An employee named boss (name: Mark, city: Den Haag, monthly salary: 10000, department: Management). Note: use the array you just created.
      2. An employee named employee (name: Caroline, city: Delft, monthly salary: 4000, department: Support);
      3. A freelancer named assistant (name: Klaas, city: Diemen, hourly rate: 50,00, department: Documentation);
      4. A freelancer named projectLeader (name: Ronald, city: Zaandam, hourly rate: 80,00, department: Operations);
    3. Hire Klaas for 160 hours.
    4. Hire Ronald for 320 hours.
    5. Create an array of type Person with four objects.
    6. Add the employees boss and employee and the freelancers assistant and projectLeader to the array.
    7. Add a method below your Main method with the signature ShowYearlyIncome(Person person) that displays the text "Name earns yearlyIncome per year" on the screen.
    8. Call this method for each of the four items in your array using a for-loop, so that the output looks like:
    1
    2
    3
    4
    Mark earns 130000,00 per year
    Caroline earns 48000,00 per year
    Klaas earns 8000,00 per year
    Ronald earns 25600,00 per year