UNIVERSITY EXAMINATIONS: 2012/2013
EXAMINATION FOR THE BACHELOR OF SCIENCE IN
BIT 2204 JAVA PROGRAMMING
DATE: AUGUST, 2013 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and Any Other TWO Questions
a) What is the relevance of the following keywords as used Java Programming? Give
examples to support your answer.
b) Create a class named Sweets. Its main() method holds an integer variable named
numberofSweets to which you will assign a value. Create a method to which you pass
numberofSweets. The method displays the sweets in dozens. For example, 40 sweets
is 3 dozens and 4 left over.
c) Create a class named Shirt with data fields for collar size and sleeve length. Include a
constructor that takes arguments for each field. Also include a String class variable
named material and initialize it to “cotton”. Write a program TestShirt to instantiate 3
Shirt objects with different collar sizes and sleeve lengths, and then display all the
data, including material, for each shirt.
d) Copy and complete the following table about access modifiers (The first one has been
done as an example) [6 Marks]
Modifier Same class Same package Sub class universe
public Yes Yes Yes Yes
e) Interfaces are quite useful in programming (Java). Explain Four uses of interfaces
f) Explain the meaning of the following keywords
ii). Instanceof [4 Marks]
a) 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.
b) 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.
c) 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. [20 Marks]
a) Comments are crucial to a programmer. Give two uses of comments in a program and
describe 3 types of comments used in Java [5 Marks]
b) Computer programs are very closely tied to the specific hardware and operating
system they run. A Windows program will not run on a computer that only runs DOS.
A Mac application can’t run on a UNIX workstation. VMS code can’t be executed on
an IBM mainframe, and so on. How does java resolve this platform problem?
c) Java is garbage collected. What do you understand by this statement?
d) The Fibonacci series is give as 0,1,1,2,3,5,8,13…. Where the next term is given as
fib(n-1)+fib(n-2). Eg. The next term is given as 8+13 = 21.
Using while control construct, write a program in Java to compute and display the
first 50 terms, 50 exclusive. [8 Marks]
a) Explain the difference between static and non-static member of a class.
b) Define inner class in Java [2 Marks]
c) What is the relevance of the following keywords?
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.
a) Define serialization as applied to Java Programming Language.
b) What are synchronized methods and synchronized statements?
c) Differentiate between the following
i). superclass and subclass
ii). overloading and overriding
iii). Aggregation and containment
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