7 Interfaces and volunteers
In this assignment you will modify the class diagram as follows:
- A
Volunteerclass is added. A volunteer can also be hired, but at zero rate. - The
Hire(int hours)method is only needed forVolunteerandFreelancerand is placed in an interface. -
Persons are sorted using the
IComparableinterface. -
If needed, retrieve the OOP Company project up to chapter 6 from DLO. It contains the classes as you left them at the end of chapter 6.
-
For the
Personclass:a) Add the
IComparable<Person>interface (already done in 5 Abstract Person and polymorphism).
b) TheCompareTo()method sorts by the name of a person (already done). -
Create an interface named
IHireablein theModelsfolder with the methodHire(int hours). The code for the interface is:1 2 3 4 5 6 7
namespace Company.Models { public interface IHireable { void Hire(int hours); } } -
Add the interface to the
Freelancerclass and override theHire()method. -
Add the
Volunteerclass to theModelsfolder according to the class diagram:a) The
Hire()method does the same as in theFreelancerclass.
b) TheCalculateYearlyIncome()method always returns 0.
c) TheToString()method returns "name lives in city and works at department name at location and is a volunteer". -
In the
Mainmethod of the launcher:a) Use the existing code and add the following four volunteers to the list:
1 2 3 4
people.Add(new Volunteer("Ambi", "Amsterdam", departments[0])); people.Add(new Volunteer("Naledi", "Gaborone", departments[1])); people.Add(new Volunteer("Ceren", "Istanbul", departments[2])); people.Add(new Volunteer("Haining", "Shaoxing", departments[3]));b) Hire all volunteers for 160 hours.
c) Sort the list alphabetically.
d) Add code to get the following output (alphabetically sorted by name):1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Ambi lives in Amsterdam and works at department Operations at Hilversum and is a volunteer Ambi earns € 0,00 per year Angelique lives in Rotterdam and works at department Management at Almere and is an employee with right to a bonus Angelique earns € 65.000,00 per year Anne lives in Zwolle and works at department Operations at Hilversum and is a freelancer with an hourly rate of 40 Anne earns € 12.800,00 per year Caroline lives in Delft and works at department Support at Amsterdam and is an employee without right to a bonus Caroline earns € 48.000,00 per year Ceren lives in Istanbul and works at department Management at Almere and is a volunteer Ceren earns € 0,00 per year Haining lives in Shaoxing and works at department Documentation at Gouda and is a volunteer Haining earns € 0,00 per year Jannie lives in Utrecht and works at department Operations at Hilversum and is a freelancer with an hourly rate of 60 Jannie earns € 19.200,00 per year Klaas lives in Diemen and works at department Documentation at Gouda and is a freelancer with an hourly rate of 50 Klaas earns € 16.000,00 per year Mark lives in Den Haag and works at department Management at Almere and is an employee with right to a bonus Mark earns € 130.000,00 per year Naledi lives in Gaborone and works at department Support at Amsterdam and is a volunteer Naledi earns € 0,00 per year Ronald lives in Zaandam and works at department Operations at Hilversum and is a freelancer with an hourly rate of 80 Ronald earns € 25.600,00 per year