SECTION B:
Kindly study the class diagram
underneath.
below
and write code
to fulfil the
[30 marks]
requirements given
Athlete
EjisportName: String
|
(Ei hoursTrained: Integer.
Person
b name: Sting |
‘il weight: Real
5 « ite sei
hon
porialn a ae
Gi earnings(Real): Real
:
—
category
!
_ from Sportsinterface} —
“individualSport
EteamSport
1.
Create the classes Athlete and Person as given in the class diagram. Add at least two
constructors for each class, including a full constructor in each. Take note that all fields
given as Real in the class diagram represent the type double.
(5 marks)
2.
Define Sportsinterface that has an abstract method weeklyEarnings(), which returns a
double and receives one parameter of type double. Also add an enum category as shown in
the class diagram above.
(4 marks)
3.
Implement the SportsInterface assuming that earnings are proportional to the
hoursTrained daily. This means you get weeklyEarnings by multiplying the hoursTrained by
- an athlete with the daily wageRate of the sport as given in the table below:
(5marks)
sportName
wageRate
tennis
1700
soccer
2100
rugby
1200
4.
Assuming that weeklyEarnings should not exceed 100 thousand weekly for each athlete,
add a custom exception, AthleteException that will be thrown in the event that this
condition is not met.
Add all necessary code to handle this exception.
(7 marks)
5.
In the driver class do the following operations:
a.
Create at least two Athlete objects using different constructors in (1). (2 marks)
b.
Demonstrate polymorphism and write an appropriate comment.
(2 marks)
Cc.
Display all the properties of the objects you created to the screen. (2 marks)
6.
Comments, readability and use of conventions.
[END]
(3 marks)
Page 2 of2