0% found this document useful (0 votes)
21 views3 pages

Soen 305

The document is an examination paper for SOEN 305: Object Oriented Programming II using Java at Kisii University, intended for third-year software engineering students. It includes various questions covering object-oriented programming concepts, Java class creation, exception handling, and inheritance. Students are required to answer question one and any two additional questions within a two-hour timeframe.

Uploaded by

makalicaroh
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)
21 views3 pages

Soen 305

The document is an examination paper for SOEN 305: Object Oriented Programming II using Java at Kisii University, intended for third-year software engineering students. It includes various questions covering object-oriented programming concepts, Java class creation, exception handling, and inheritance. Students are required to answer question one and any two additional questions within a two-hour timeframe.

Uploaded by

makalicaroh
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/ 3

SOEN 305

KISII UNIVERSITY
UNIVERSITY EXAMINATIONS
THIRD YEAR EXAMINATION FOR THE AWARD OF THE DEGREE OF
BACHELOR OF SCIENCE IN SOFTWARE ENGINEERING
FIRST SEMESTER 2022/2023
[SEPTEMBER-DECEMBER, 2022]

SOEN 305: OBJECT ORIENTED PROGRAMMING II USING JAVA

STREAM: Y3S1 TIME: 2 HOURS

DAY: TUESDAY, 9:00 – 11:00 AM DATE: 20/12/2022


INSTRUCTIONS
1. Do not write anything on this question paper.
2. Answer question ONE and any other TWO questions.

QUESTION ONE (30 marks)

(a) In your words, describe object oriented programming (2 marks)


(b) What are abstract methods? Describe the circumstances in which an abstract
method would be appropriate (2 marks)
(c)
i. Create a class called invoice that a hardware store might use to represent
an
invoice for an item sold at the store. An invoice should include 4 pieces of
information as instance variables; a part number (type string), a part
description
(type string), a quantity of the item being purchased (type int) and a price
per item(double). (5 marks)
ii. . Your class should have a constructor that initializes the 4 instance
variables.
Provide a set and a get method for each of the 4 instance variables. In
addition
provide a method named getInvoiceAmount that calculates the invoice
amount i.e. multiplies the quantity by the price per item, then returns the
amount as a double value. If the quantity is not positive, it should be set to
0.0. (5 marks)
iii. Write a test application named invoiceTest that demonstrates class
invoice’s
capabilities. (5 marks)
(d) Explain how:
i. The super reference is important to a child class. (2 marks)
ii. Inheritance support polymorphism (2 marks)
(e) Describe the principles of the object oriented paradigm (7 marks)

Page 1 of 3
QUESTION TWO (20 MARKS)

(a) With relevant example java codes, differentiate between super and this
references as used in object oriented programming. (6 marks)

(b) Create a Person class that includes fields for last name, first name, and zip code.
Include a default constructor that initializes last name, first name, and zip code
to “X” if no arguments are supplied. Also include a display function. Write a main()
function that instantiates and displays two Person objects: one that uses the
default values, and one for which you supply your own values.
(6 marks)
(c) With relevant java code examples, differentiate between method overriding and
method overloading as used in object oriented programming.
(8 marks)

QUESTION THREE (20 MARKS)


(a) The Explain the notion of package access in Java. Explain the negative aspects
of package access. (5 marks)

(b) Explain the three ways in which a java program can be designed to process an
exception. (4 marks)

(c) Explain why a static method cannot refer to an instance variable. (5 marks)
(f) Study the following simple Java program carefully.
class t {
public static void main(String[] args)) {
int i = 0, m = 0;
while (i++ < 10) m += i*i;
StdOut.println(m);
}
}
What does the program do when run? (5 marks)

(g) Design and implement an application that reads an integer value and prints the
sum of all even integers between 2 and the input value, inclusive. Print an error
message if the input value is less than 2. Prompt accordingly.
(5 marks)

QUESTION FOUR (20 MARKS)

(a) In an object oriented inheritance hierarchy, each level is a more specialized


form of the preceding level. Give an example of a hierarchy found in everyday
life that has this property. Illustrate your answer using a diagram.
(5 marks)

(b) What will be the output of the following code? (6 marks)

Class Q3Main{
public static void main(String args[]){
QuestionTFour() q4;
q4=new QuestionTFour();
q4.init();
Page 2 of 3
q4.count=q4.increment() + q4.increment();
System.out.println(q4.increment());
}
}
class QuestionTFour(){
public int count;
public void init(){
count=1;
}
public int increment(){
count=count+1;
return count;
}
}

(c) Discuss the role of a constructor and state any two properties of a
constructor. (3 marks)

(d) What does it mean when: (6 marks)


i. a method is declared final
ii. a class is defined as final

QUESTION FIVE (20 MARKS)

a) Imagine you are given the task of designing an airline reservation system that
keeps tracks of flights for a commuter airline. List the classes you think would be
necessary for designing such a system. Describe the data values and methods you
would associate with each class you identify.
(8 Marks)
b)
i. Create a class named Student. A Student has fields for an ID number, number
of credit hoursearned, and number of points earned. (For example, many
schools compute grade point averagesbased on a scale of 4, so a three-credit-
hour class in which a student earns an A is worth 12 points.) Include methods
to assign values to all fields. A Student also has a field for grade point average.
Include a method to compute the grade point average field by dividing points
by credit hoursearned. Write methods to display the values in each Student
field. (8 Marks)

ii. Write a class named ShowStudent that instantiates a Student object from the
class you created. Compute the Student grade point average, and then display
all the values associated with theStudent. (4 Marks)

Page 3 of 3

You might also like