OOP521S - OBJECT ORIENTED PROGRAMMING -2ND OPP - JAN 2020


OOP521S - OBJECT ORIENTED PROGRAMMING -2ND OPP - JAN 2020



1 Page 1

▲back to top


NAMIBIA UNIVERSITY
OF SCIENCE AND TECHNOLOGY
Faculty of Computing and Informatics
Department of Computer Science
QUALIFICATION: Bachelor of Computer Science
QUALIFICATION CODE: 07BACS
COURSE: Object Oriented Programming
DATE: January 2020
DURATION: 3 HOURS
LEVEL: 5
COURSE CODE: OOP521S
SESSION: 2
MARKS: 100
SUPPLEMENTARY/SECOND OPPORTUNITY EXAMINATION QUESTION PAPER
EXAMINER
MODERATOR:
MR SIMON H. MUCHINENYIKA
MR HERMAN KANDJIMI
MRS ROSETHA KAYS
MRS NDINELAGO NASHANDI
MR STEVEN TJIRASO
MR COLIN STANLEY
THIS EXAM PAPER CONSISTS OF 2 PAGES
(Excluding this front page)
INSTRUCTIONS
This is a closed book examination with two sections; A and B.
Answer ALL questions in a separate writing booklet provided to you.
Total marks per section are indicated in [], and () per question.
For Section A, answer each question on a new page.
NUST’s examination rules and regulations apply.

2 Page 2

▲back to top


SECTION A:
[70 marks]
Cleary explain and distinguish the following terms from one another. Give example
code in ALL cases.
1.
primitive types and reference types
(10 marks)
2.
constructor overload and implicit constructor invocation
(10 marks)
3.
arrays and arraylists
(10 marks)
4,
default methods and abstract methods
(10 marks)
5.
is-a and has-a
(10 marks)
6.
throws clause and throw statement
(10 marks)
7.
composition and aggregation
(10 marks)
Page 1 of2

3 Page 3

▲back to top


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

4 Page 4

▲back to top


NAMIBIA UNIVERSITY
OF SCIENCE AND TECHNOLOGY
Faculty of Computing and Informatics
Department of Computer Science
QUALIFICATION: Bachelor of Computer Science
QUALIFICATION CODE: 07BACS
COURSE: Object Oriented Programming
DATE: January 2020
DURATION: 3 HOURS
LEVEL: 5
COURSE CODE: OOP521S
| SESSION: 2
MARKS: 100
SUPPLEMENTARY/SECOND OPPORTUNITY EXAMINATION QUESTION PAPER
EXAMINER
MR SIMON H. MUCHINENYIKA
MR HERMAN KANDJIMI
MRS ROSETHA KAYS
|
MRS NDINELAGO NASHANDI
:"
|
MR STEVEN TJIRASO
MODERATOR: |
MR COLIN STANLEY
THIS EXAM PAPER CONSISTS OF 2 PAGES
(Excluding this front page)
INSTRUCTIONS
. This is a closed book examination with two sections; A and B.
. Answer ALL questions in a separate writing booklet provided to you.
. Total marks per section are indicated in [], and () per question.
For Section A, answer each question on a new page.
NUST’s examination rules and regulations apply.

5 Page 5

▲back to top


SECTION A:
[70 marks]
Cleary explain and distinguish the following terms from one another. Give example
code in ALL cases.
1.
primitive types and reference types
(10 marks)
2.
constructor overload and implicit constructor invocation
(10 marks)
3.
arrays and arraylists
(10 marks)
4.
default methods and abstract methods
(10 marks)
5.
is-a and has-a
(10 marks)
6.
throws clause and throw statement
(10 marks)
7.
composition and aggregation
(10 marks)
Page 1 of2

6 Page 6

▲back to top


SECTION B:
[30 marks]
Kindly study the class diagram below and write code to fulfil the requirements given
underneath.
Athlete
Person
[il sportName: String .
[31 hoursTrained: Integer
b> ‘name: String |
El weight: Real
“« Interface»
Sportsinterface
BD
&, earnings(Real): Real
category
(from Sportsinterface)
= individualSport
=a teamSport
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:
(Smarks)
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 of 2