0% found this document useful (0 votes)
23 views5 pages

Cit383 2022 2

Cit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views5 pages

Cit383 2022 2

Cit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

NATIONAL OPEN UNIVERSITY OF NIGERIA

University Village, Plot 91, Jabi Cadastral Zone, Nnamdi Azikiwe Expressway, Abuja

FACULTY OF SCIENCES
Computer Science Department
2022_2 EXAMINATION

Course Code: CIT383


Course Title: Introduction to Object-Oriented Programming
Credit: 2 Units
Time Allowed: 2 hours
Instruction: Answer Questions One (1) and any other THREE (3) questions

Question One (30 marks) COMPULSORY


A CSV (= “comma separated values”) file contains Employee records formatted in the
example below. Each record specifies the name of the person followed by their job roles.
Each record is on separate lines. The fields of each record are separated by a comma.
Grace Omotoso, HR Manager
Richard Jacobs, System Analyst
Esther Martins, Database Administrator

A programmer has created the following class to represent the employee records
public class Employee {

private String Name;

private String Role;

a) Write a constructor for class Employee. The constructor should have two parameters
which initialise the object fields.
(6 marks)

b) In class Employee, write an appropriate accessor method getEmployeeRecord() to display


the employee’s name and job role formatted in the example below:

Page 1 of 5
Grace Omotoso is the HR Manager

Your method should not return any variable.


(6 marks)
c) The programmer wants to include the date the employee was hired for new employees.
Create a class Date that has three hidden parameters – day, month and year, an
appropriate mutator method setDateVariables to initialise their values, and a toString()
method which returns a string in the format dd/mm/yyyy.
(10 marks)
d) Write an executable class called NewEmployee which captures and displays the details of a
new employee called Rachael Gambo with Java Programmer as her job role and hired on
the 20th of September 2022 in the format below:
Rachael Gambo is the Java Programmer
hired on 20/09/2022
(8 marks)

Question Two
a) To overload constructors and methods, we simply declare them with different signatures.
What is meant by signature?
(3 marks)
b) Create a class called OverloadedMethods and provide three overloaded public method
called FunctionOverload within this class. The first method should accept two integer
values as its arguments and return an integer. The second method should accept an
integer value, a double value and another integer value in that order and return a double.
The third method should accept two double values as its argument and not return an
argument.
(10 marks)
c) Within the same class OverloadedMethods and provide a constructor for the class that
behaves like the default constructor.
(2 marks)
d) Highlight five (5) features of Interfaces in Java. (5 marks)

Question Three
a) Define Encapsulation. (3 marks)
b) Define Inheritance. (3 marks)
c) Define Polymorphism. (3 marks)

Page 2 of 5
d) Given a class CourseMembers as shown below, modify the class into a form that promotes
data hiding.
public class Member {
protected String firstname;
protected String lastname;
protected int mathscore;
protected int englishscore;
protected int sciencescore;

public Member (String first, String last, int course1, int course2,
int course3)
{
Firstname = first;
Lastname = last;
Mathscore = course1;
Englishscore = course2;
Sciencescore = course3;
}
public double getAverage()
{
return (mathscore + englishscore + sciencescore)/3;
}

(5 marks)
e) Given a class cup as follows:
class cup {
void addLiquid (Liquid liq){
// swirl clockwise
}
}

Create two classes both with the name teaCup. One class will inherit the method
addLiquid() and the other will override it.

(6 marks)

Question Four
a) What is an Object? (2
marks)

b) What is meant by Object Instantiation? (1


marks)

Page 3 of 5
c) Differentiate between an executable class and a non-executable class. (2
marks)

d) Given a non-executable class TimeClass as follows:


public class TimeClass

private int hour;


private int minute;
private int second;

public TimeClass(int myHour, int myMinute, int mySecond)


{
hour = myHour;
minute = myMinute;
second = mySecond;

Create three accessor methods to retrieve the value of each these variables and a
method to format the output of the time to 12:30:45
(6 marks)
e) Create an executable class CircleProperties that prompts a user to enter the radius of a
circle and computes the perimeter and the area of the circle. You must make use of the
Math.PI static field of the Math class for these computations. The format for receiving
the radius and displaying the results is as follows:
Enter a value for Radius:
The Perimeter is:
The Area is:

(9 marks)

Question Five
a) Enumerate two (2) functions of a destructor. (3 marks)
b) What is meant by Data hiding? (5 marks)
c) Consider a Java package named – Employee – with the following classes – Name,
Address, Department – write the syntax for:
i. importing each class individually (for all classes)
ii. importing all classes (at the same time).
iii. Instantiating an object of the classes – Name and Address.
(7 marks)
Page 4 of 5
d) Outline the stand syntax used to declare an indexer (3
marks)
e) State two limitations of overloading True and False operators (2
marks)

Page 5 of 5

You might also like