Soen 305
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]
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)
(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)
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)
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