UNIVERSITY EXAMINATIONS: 2012/2013
EXAMINATION FOR THE BACHELOR OF SCIENCE IN
INFORMATION TECHNOLOGY
BIT 2204 JAVA PROGRAMMING
DATE: AUGUST, 2013 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and Any Other TWO Questions
QUESTION ONE
a) What is the relevance of the following keywords as used Java Programming? Give
examples to support your answer.
i). new
ii). extends
iii). implements
iv). throws
[4 Marks]
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.
[6 Marks]
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.
[6 Marks]
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
protected
default
private
e) Interfaces are quite useful in programming (Java). Explain Four uses of interfaces
[4 Marks]
f) Explain the meaning of the following keywords
i). Final
ii). Instanceof [4 Marks]
QUESTION TWO
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]
QUESTION THREE
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?
[4Marks]
c) Java is garbage collected. What do you understand by this statement?
[3 Marks]
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]
QUESTION FOUR
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 FIVE
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]