0% found this document useful (0 votes)
27 views

(QUESTIONS) Sup Exam Object-Oriented Programming With Java (Wed, 7 July 2024)

Uploaded by

aaron banda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

(QUESTIONS) Sup Exam Object-Oriented Programming With Java (Wed, 7 July 2024)

Uploaded by

aaron banda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1

THE UNIVERSITY OF ZAMBIA


IN ASSOCIATION WITH
ZAMBIA UNIVERSITY COLLEGE OF TECHNOLOGY

BACHELOR OF INFORMATION & COMMUNICATIONS TECHNOLOGY WITH EDUCATION (BICT)


BACHELOR OF INFORMATION TECHNOLOGY (BIT)
BACHELOR OF SOFTWARE ENGINEERING (BSE)
BACHELOR OF CYBER SECURITY (BCS)

FRIDAY, 7th JULY 2024 SUPLEMENTARY EXAMINATIONS


OBJECT-ORIENTED PROGRAMMING WITH JAVA
COURSE CODE: BIT 3300 / ICT 3350
TIME: 14:00HRS DURATION: 3 HOURS

INSTRUCTIONS TO CANDIDATES
1. Enter your STUDENT ID on the ANSWER BOOKLET provided.
2. There are SEVEN (7) QUESTIONS in this paper [TWENTY (20) MARKS] each.
3. The paper has two secMons, SECTIONS A and B. SECTION A is compulsory.
4. Choose any three (3) quesMons from SECTION B.
5. Answer five (5) quesMons altogether giving a total of 100 MARKS
6. Mark the aXempted QUESTION NUMBER on the answer booklet provided.
7. Ensure that your handwriMng is clear and readable.

DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD

Page 1 of 4
2

SECTION A – COMPULSORY (ANSWER ALL QUESTIONS IN THIS SECTION)


QUESTION 1 [20]
A. Write a Java program that prompts the user to enter Mme in [5]
12-hour notaLon. The program then outputs the Mme in 24-hour notaLon.
Your program must contain three excepMon classes:
InvalidHrExcep, InvalidMinExcep, and InvalidSecExcep.

If the user enters an invalid value for hours, then the program should throw
and catch an InvalidHr object.
Similar convenMons for the values of minutes and seconds.
NOTE: You are NOT required to include any constructors, ge3ers, se3ers
and toString() Methods in your solu9on.

QUESTION 2 [20]
A. A point in the x-y plane is represented by its x-coordinate and y-coordinate.
Design the class Point that can store and process a point in the x-y plane
in Java.
Include Java operaMons on a point, such as showing the point, seang the
coordinates of the point, prinMng the coordinates of the point, returning
the x-coordinate, and returning the y-coordinate.

Page 2 of 4
3

SECTION B - ANSWER ANY THREE (3) QUESTIONS OF YOUR CHOICE

QUESTION 3 [20]
A. Write a Java program that reads a sentence as input and converts each word to
“Pig LaLn”.
In one version of Pig LaLn, you convert a word by removing the first leXer,
placing that leXer at the end of the word, and then appending “ay” to the word.
Here is an example:
English: I SLEPT MOST OF THE NIGHT
Pig LaMn: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY

QUESTION 4 [20]
A. Suppose that class Three is derived from class Two and class Two is derived
from class One and each class has instance variables.
Suppose that an object of class Three enters its scope, so the
constructors of these classes will execute.
1. Design the classes described above in a Java Program [10]
2. Determine the order in which the constructors of these classes
will execute in. [10]

QUESTION 5 [20]

A. Class-design guidelines are helpful for designing sound classes.


For each design guideline listed below, give a brief descripMon about its
purpose as a class design guideline: [8]
a. Cohesion
b. Consistency
c. EncapsulaMon
d. Clarity
e. Completeness
f. Instance vs. StaMc
g. Inheritance vs. AggregaMon
h. Interfaces vs. Abstract Classes

Page 3 of 4
4

B. Write a method named findElementIndex that searches a numeric array named


numbers for a specified value named target. The method should return the
subscript of the element containing the value if it is found in the array.
If the value is not found, the method should throw an excepMon of the
ExcepLon class with the error message “Element not found”. [12]

QUESTION 6 [20]

A. Write an excepMon class called NegaLveNumberExcepLon that can be


thrown when a negaMve number is passed to a method.
The excepMon class should contain two constructors that: [5]
• Constructs a new NegaMveNumberExcepMon with the specified detail
message. [5]
• Constructs a new NegaMveNumberExcepMon with the specified detail
message and cause. [5]
Include documentaMon comments for each block of code. [5]

QUESTION 7 [20]
A. Explain the concept of staMc class members in Java, and provide an
example of when you would use a staMc variable and a staMc method. [2]
B. Write a Java method that takes an object of a Person class as an argument,
modifies its state, and returns the modified object. [5]
C. Create a Circle class with one instance variable and a non-staMc
method that returns an object of the same class. [5]
D. Discuss the importance of overriding the toString() method in Java classes,
and provide an example implementaMon for a custom class. [8]

Page 4 of 4

You might also like