Bit 2204A Java Programming Question Paper

Bit 2204A Java Programming 

Course:Bachelor Of Science In Information Technology

Institution: Kca University question papers

Exam Year:2014



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.
e)
[6 Marks]
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.
f)
[5 Marks]
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]
1
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.
i)
ii)
iii)
iv)
v)
vi)
vii)
viii)
c)
[4 Marks]
i
i
i
i
i
i
i
i
nt
nt
nt
nt
nt
nt
nt
nt
[
[
[
[
] a
] a
10]
] a;
a =
[][]
[][]
[] a
= i nt [ 10] ;
= new i nt [ 10] ;
a = new i nt [ 10] ;
{ 1, 2, 3} ;
a = { { 1, 2, 3} , { 1, 2, 3} } ;
a = new i nt [ 10] ;
= { 1, 2, 3} ; i nt [ ] b = a;
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?
2
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) [3 Marks]
Explain two ways in which an interface differs from an abstract class.
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.
c)
[4 Marks]
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
3
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]
4






More Question Papers


Exams With Marking Schemes

Popular Exams


Mid Term Exams

End Term 1 Exams

End Term 3 Exams

Opener Exams

Full Set Exams



Return to Question Papers