(QUESTIONS) Sup Exam Object-Oriented Programming With Java (Wed, 7 July 2024)
(QUESTIONS) Sup Exam Object-Oriented Programming With Java (Wed, 7 July 2024)
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.
Page 1 of 4
2
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
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]
Page 3 of 4
4
QUESTION 6 [20]
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