BIT 2204A JAVA PROGRAMMING KCA Past Paper

UNIVERSITY EXAMINATIONS: 2013/2014
ORDINARY EXAMINATION FOR THE BACHELOR OF SCIENCE
IN INFORMATION TECHNOLOGY
BIT 2204A JAVA PROGRAMMING
DATE: AUGUST, 2014 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and any other TWO

QUESTION ONE
a) Explain any four characteristics that make java language overcome some of the
limitations of its predecessors. [8 Marks]
b) Using a diagram, explain the concept of Java platform and its importance.
[4 Marks]
c) Write a Java console application that inputs the radius and then computes and
displays the area and circumference of the circle. Use console window for inputs and
outputs. [4 Marks]
d) Write a Java program that inputs three integer numbers using Inputbox dialogs and
computes the sum and average of the numbers. The program should then display the
sum and average by use of a message box dialog. Your program should confirm from
the user on whether to continue or not. If the user clicks “Yes” then the program
computes another set of numbers, and “No” the program exits. [6 Marks]
e) Create a Java application that defines a class named Person. It should have instance
variables to record name, age and salary and which are of types String, integer and
floating point respectively. Create a Person object and assign and then display the
instance variable values using the console window. [5 Marks]
f) Write an applet program that displays the words “Long Live Kenya!!!” at the center
of the applet. The words should be displayed using red colour in a yellow
background. [3 Marks]
QUESTION TWO
a) Describe the use of the this keyword in Java. [2 Marks]
b) Among the following statements, identify the ones that will not cause a compile-time
error. [4 Marks]
i) i nt [ ] a = i nt [ 10] ;
ii) i nt [ ] a = new i nt [ 10] ;
iii) i nt [ 10] a = new i nt [ 10] ;
iv) i nt [ ] a;
v) i nt a = { 1, 2, 3} ;
vi) i nt [ ] [ ] a = { { 1, 2, 3} , { 1, 2, 3} } ;
vii) i nt [ ] [ ] a = new i nt [ 10] ;
viii) i nt [ ] a = { 1, 2, 3} ; i nt [ ] b = a;
c) Consider the following Java program
public class HIthere {
public static void greeting(int x)
{
if (x < 10)
{
System.out.print(“Hello,”);
}
else
{
System.out.print(“Bonjour,”); /* French
for “Hello”*/
}
x = x – 5;
}
public static void main(String[] args)
{
int x = Integer.parseInt(args[0]);
greeting(x);
if (x < 3)
{
System.out.println(” world.”); // Anglais
//pour “monde”
}
else
{
System.out.println(” monde.”);
}
}
}
What will be printed by this program in the following cases?
i) java HIthere 10
ii) java HIthere 7 [4 Marks]
d) Write a Java application program to be used to calculate the area and perimeter of the
rectangle. Create a Rectangle class with private instance variables length and width
and methods to calculate and return the perimeter and area of the rectangle
respectively. It also has modifier (set) and accessor (get) methods for inputting and
outputting the length and the width. The modifier methods should verify that the
length and width are each a floating point number greater that 0.0 and less than 20.0.
Define another class that has a main method and used to instantiate the rectangle
object and then send relevant messages to compute for area and perimeter of the
rectangle. Have both inputs and outputs through console window. [10 Marks]
QUESTION THREE
a) Define the term Interface in relation to Java programming. [2 Marks]
b) Explain briefly the significance of using Interface when programming. [3 Marks]
c) Explain two ways in which an interface differs from an abstract class. [3 Marks]
d) Write a Java program to determine the area and perimeter of a circle and rectangle
respectively. Your program should consist of an interface and classes that
implements the interface and used to compute for the area and perimeter of the circle
and rectangle. All classes uses constructors to initialize the data members and have
methods area () and perimeter (), which are used to compute for the area and
perimeter of the respective shapes. Include a main class to demonstrate the working
of the program. [12 Marks]
QUESTION FOUR
a) Explain any four benefits offered by Applets, when developing Internet based
applications. [4 Marks]
b) Briefly describe the diffrence between how an applet and frame would implement
the same GUI components to render the same look in an iterface. [4 Marks]
c) Write a Java Applet that displays the GUI that contains three text fields, three labels
and a button as depicted below. Your applet should allow the student to enter the
registration number and average mark in the respective text fields and then grades
the student as “Pass” if the average mark is greater than or equal to 50 and “Fail”
otherwise after a click of the button. Use the text field labeled “Student Grade” to
display the grade. Use the FlowLayout to arrange the GUI widgets. [12 Marks]


QUESTION FIVE
a) Explain the role played by each of the following :
i) Event source
ii) Event object
iii) Event listener [6 Marks]
b) Write a program that adds or subtracts numbers entered by the user, depending on
the button clicked. The program should have an interface similar to the one shown
below.

[14 Marks]

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

Written by