Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

EXAMINATION

FACULTY OF SCIENCE AND TECHNOLOGY

PROGRAMME(S):

SESSION:DAY/EVENING
MODULE CODE AND TITLE: LEVEL:
2108,2101 OBJECT ORIENTED DIT, BIT, BCS, BSF
PROGRAMMING WITH JAVA
DATE: TIME:
June, 2024

DURATION: TOTALMARKS:
6 Hours 100

EXAMINER/LECTURER: MODERATOR:
Mr. Bazigu Alex Dr. David Kakeeto

INSTRUCTIONS TO THE CANDIDATE/STUDENT

1. V-class is the ONLY official examination platform.


2. Questions must be attempted in the answer booklet/sheet provided on V-class.
3. All queries should be directed to the examiner, Head of Department, or Dean.
4. You have SIX HOURS to complete this paper. No exam answer sheet shall
be accepted after the 6 hours (the system has closed).
5. This is an OPENBOOK (Online) examination.
6. Attempt 4 Questions in total. All questions carry equal marks(25 marks each).
7. Read each question carefully before beginning to type/write your answers.
8. Review the grades assigned to each question of the examination and allocate
your time accordingly.
9. Review your answers carefully before submitting your examination.
10. After submission of your exam answer sheet, Cross-Check to make sure your
examination was attached and has been sent to V-class and received a
confirmation message.
QUESTIONS

QUESTION ONE [25 MARKS]

A month is a leap month if it is divisible by 4 but not by 100 or if it is divisible by 400 based
on the Boolean expressions below.

Boolean isLeapMonth = (year %4 ===0); or isLeapMonth = isLeapMonth &&


(month%100 != 0) or isLeapMonth = isLeapMonth ||(month %400 == 0);

a) Create a Java class called “leapmonth”, declare the variable the program.
b) Write a Java program to check whether a given month is a leap month
c) Save the project in the folder created on desktop, screenshot all your program codes
and output and upload the code to GitHub Repository called Question1-leapmonth.
d) Attach the screenshot of your final output on the answer sheet and the link for your
repository

QUESTION TWO [25 MARKS]

The demand for students in institutions has finally forced Balex institute to structure their
online courses for anyone in Africa and beyond to enroll for them. The following are the details
per course as shown in the table below:

Course CourseID Tuition


Software Engineering BSE 900,000
Information Technology BIT 750,000
Computer Science BCS 800,000
Computer Engineering BCE 950,000

(a) Using Java IDE, create an application called "balex" and create a Java class called
"courses".
(b) Identify and declare the variables in a program.
(c) Develop a Java application that prompts the applicant to feed in the CourselD, and the
details of the course are returned to the screen. When the wrong code is fed into the
system, "Wrong CourselD details" should be returned.
(d) Save the project in the folder created on desktop, screenshot all your program codes
and output and upload the code to GitHub Repository called Question2-balex.
(e) Attach the screenshot of your final output on the answer sheet and the link for your
repository.

QUESTION THREE [25 MARKS]

(a) Explain the purpose of access modifiers in OOP languages


(b) Copy and complete the table below to show the access restrictions for the four access
modifiers in Java.

Access Modifier
Defining class
Class in same package
Subclass in different package
Non-subclass in different package

(c) A Java game designer wishes to store all the game preferences (e.g., player name, screen
size, music volume, etc.) within a custom Preference class.
i) Assuming each preference is stored as a unique String key mapping to a String
value, give a simple implementation of Preference that allows for efficiently setting
or updating preferences and retrieving previously set ones. Your implementation
should define an exception that is thrown when a preference key is requested but
not present.
ii) It is important that only one Preference object exists in a running game. Show how
to apply access modifiers and the Singleton design pattern to ensure this. Your
implementation should lazily instantiate the object. Is it necessary to make your
class final or Cloneable? Explain your answer.

QUESTION FOUR [25 MARKS]

You have been asked by a mathematics student to develop a Java program for him to practice
subtraction. The program randomly generates two single-digit integers, numberl and number2,
with numberl > = number2 and displays to the student a question such as "What is 9 - 2?".
After the student enters the answer, the program displays a message indicating whether it is
correct.
Required.

a) Create a Java class called "subtraction".


b) Generate two single-digit integers into numberl and number2.
c) If numberl < number2, swap numberl with number2.
d) Prompt the student to answer" What is numberl - number2? ".
e) Check the student's answer and display whether the answer is correct.
f) Save all your work in the folder created on desktop, screenshot all your program codes and
output and upload the code to GitHub Repository called Question3-Substraction
g) Attach the screenshot of your final output on the answer sheet and the link for your
repository

QUESTION FIVE [25 MARKS]

a) Bukoto Village Bank Limited would like to create a system which inputs each of the
members principal amounts of money deposited on their accounts for investment at an
interest rate determined by the management for a certain period of time. The system
calculates the value of investment after the time frame elapses. Write Java Code statements
to implement the above program using each of the following selection statements.
(i) For Loop
(ii) While Loop
b) Alexa and Balexis Merchants was contracted by L&M Limited to develop a Java
Program that prompts a user to enter any three numbers. The program then displays the
product, sum and the maximum of the numbers that the user entered in a tabular format as
illustrated below.

Product Sum Maximum

48 18 8

Write the Java Code to implement the program.


QUESTION SIX [25 MARKS]

(a) You are given the following implementation for an element of a list

(i) What does the statement super() mean?


(ii) What is the meaning of this in the line this.item = item?
(iii) What is the purpose of the annotation @Override?
(iv) Rewrite the class to be immutable. You may assume that there are no sub-classes of
Element.
(b) Use the immutable Element class to provide an implementation of an immutable class
FuncList which behaves like an int list in ML. Your class should include a constructor for
an empty list and methods head, tail and cons based on the following functions in ML.
Ensure that your class behaves appropriately when the list is empty.

(c) Another developer changes your implementation to a generic class FuncList<T> that can
hold values of any type T.
(i) This means that FuncList<T> is no longer immutable. Explain why and what
could be done to remedy this.
(ii) Java prohibits covariance of generic types. Is this restriction necessary in this
case? Explain why with an example.

You might also like