5 Abstract Person and polymorphism
-
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.
-
Make the
Personclass and theCalculateYearlyIncome()method abstract according to the class diagram. -
Adjust your
Mainmethod as follows:- Create an array named
departmentswith four departments:- The department Operations in Hilversum;
- The department Support in Amsterdam;
- The department Management in Almere;
- The department Documentation in Gouda.
- Create four persons:
- An employee named
boss(name: Mark, city: Den Haag, monthly salary: 10000, department: Management). Note: use the array you just created. - An employee named
employee(name: Caroline, city: Delft, monthly salary: 4000, department: Support); - A freelancer named
assistant(name: Klaas, city: Diemen, hourly rate: 50,00, department: Documentation); - A freelancer named
projectLeader(name: Ronald, city: Zaandam, hourly rate: 80,00, department: Operations);
- An employee named
- Hire Klaas for 160 hours.
- Hire Ronald for 320 hours.
- Create an array of type
Personwith four objects. - Add the employees
bossandemployeeand the freelancersassistantandprojectLeaderto the array. - Add a method below your
Mainmethod with the signatureShowYearlyIncome(Person person)that displays the text "Name earns yearlyIncome per year" on the screen. - 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 - Create an array named