BIT 2204 OBJECT ORIENTED PROGRAMMING II KCA Past Paper

UNIVERSITY EXAMINATIONS: 2012/2013
SECOND YEAR EXAMINATION FOR THE BACHELOR OF SCIENCE IN
INFORMATION TECHNOLOGY
BIT 2204 OBJECT ORIENTED PROGRAMMING II
DATE: DECEMBER, 2012 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and any other TWO

QUESTION ONE
a) Discuss the following elements of OOP and how they are implemented
i). Encapsulation
ii). Information Hiding
iii). Inheritance
iv). Polymorphism
(8 Marks)
b) Give SIX characteristics of Object Oriented programming language?
(6 Marks)
c) A public method named computeSum() is located in classA. Write a statement that would
call the method from within classB.
(2 Marks)
d) What will the following program output
class SetUpSite2
{
public static void statementOfPhilosophy()
{
System.out.println(“Event Handlers Incorporated is”);
System.out.println(“dedicated to making your event”);
System.out.println(“a most memorable one.”);
}
}
public class TestStatement2
{
public static void main(String[] args)
{
System.out.println
(“Calling method from another class:”);
SetUpSite.statementOfPhilosophy();
}
}
(3 Marks)
e) What is the difference between a break statement and a continue statement?
(2 Marks)
f) Create a class named Eggs. Its main() method holds an integer variable named
numberOfEggs to which you will assign a value. Create a method to which you pass
numberOfEggs. The method displays the eggs in dozens; for example, 50 eggs is 4 full
dozen (with 2 eggs remaining).
(6 Marks)
g) What is package in JAVA?
(1 Mark)
QUESTION TWO
a) Explain the difference between static and non-static member of a class.
(2 Marks)
b) Define inner class in Java
(2 Marks)
c) What is the relevance of the following keywords?
i). this
ii). instanceof
iii). Applet
(6 Marks)
d) Create a class named Monogram. Its main() method holds three character variables that
hold your first, middle, and last initials, respectively. Create a method to which you pass
the three initials and which displays the initials twice—once in the order first, middle,
last, and a second time in traditional monogram style (first, last, middle).
(6 Marks)
e) When does a name clash occur?
(2 Marks)
f) Briefly state the difference between static and dynamic modeling
(2 Marks)
QUESTION THREE
a) Define serialization as applied to Java Programming Language
(2 Marks)
b) What are synchronized methods and synchronized statements?
(6 Marks)
c) Differentiate between the following
i). superclass and subclass
ii). overloading and overriding
iii). Aggregation and containment
(6 Marks)
d) Create a program that displays the result of a sales transaction. The calculation requires
three numbers. The first number represents the product price. The second number is the
salesperson commission. These two numbers should be added together. The third value
represents a customer discount; subtract this third number from the result of the addition.
Create two classes. The first class, Transaction, contains the method to do the calculation.
The three numbers are passed to this method by a statement in the other class. The display
is performed in the class that calls the calculation method
(6 Marks)
QUESTION FOUR
a) Does garbage collection guarantee that a program will not run out of memory? Support
your answer
(3 Marks)
b) Create a class named Student. A Student has fields for an ID number, number of credit
hours earned, and number of points earned. (For example, many schools compute grade
point averages based 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 hours earned. Write methods to display the values in each
Student field.
(6 Marks)
c) 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 the Student.
(4 Marks)
d) Create a constructor method for the Student class you created. The constructor should
initialize each Student’s ID number to 9999 and his or her grade point average to 4.0.
Write a program that demonstrates that the constructor works by instantiating an object
and displaying the initial values.
(6 Marks)
e) Define the term scope
(1 Mark)
QUESTION FIVE
a) Create a class named Commission that includes three variables: a double sales figure, a
double commission rate, and an integer commission rate. Create two overloaded methods
named computeCommission(). The first method takes two double arguments representing
sales and rate, multiplies them, and then displays the results. The second method takes
two arguments: a double sales figure and an integer commission rate. This method must
divide the commission rate figure by 100.0 before multiplying by the sales figure and
displaying the commission. Supply appropriate values for the variables, and write a
main() method that tests each overloaded method.
(12 Marks)
b) Write a program that stores an employee’s hourly pay rate and hours worked. Compute
gross pay (hours times rate), withholding tax, and net pay (gross pay minus withholding
tax). Withholding tax is computed as a percentage of gross pay based on the following:

(8 Marks)

(Visited 171 times, 1 visits today)
Share this:

Written by