BIT2204A   JAVA PROGRAMMING . KCA Past Paper

UNIVERSITY EXAMINATIONS: 2016/2017
EXAMINATION FOR THE DEGREE OF BACHELOR OF SCIENCE IN
INFORMATION TECHNOLOGY
BIT2204A JAVA PROGRAMMING
FULL TIME/PART TIME
SPECIAL/SUPPLEMENTARY EXAMINATION
DATE: JULY, 2017 TIME: 2 HOURS
INSTRUCTIONS: Answer Question One & ANY OTHER TWO questions.

QUESTION ONE
a) Briefly explain the meaning of the following terms and write Java code that demonstrates
its usage. [6 Marks]
i) Variable
ii) Method
iii)Class
b) Explain the following java code including expected output if the program is executed.
[4 Marks].
class test1
{
public static void main(String[] args) {
float f = 1;
System.out.println(++f); // line 2
}}
c) Write while-loop structure using a well commented java programming code that can print
the following five numbers [4 Marks]
1,2,3,4,5
d) Write a do-while loop structure using a well commented java programming language that
can print a menu with the following list of items. comment the code [4 Marks]
Hotel Menu
1. breakfast
2. lunch
3. dinner
4. Exit
e) Write a class named student that instantiates a Bsc_student object from the class you created.
Prompt the a user to enter personal details such as idno, name, Course and then display all the values
entered by the user (6 Marks)
f) Briefly explain the meaning of the following terms and write a java code that demonstrates
how they can be implemented (6 Marks)
i) For loop structure
ii) If/else structure
iii) switch structure
QUESTION TWO
a) Briefly explain the meaning of the following terms in the context of java programming.
Write java code snippet that demonstrates implementation of each case. [4 Marks]
i). one dimension Array
ii) Multi-dimension array
b). Briefly explain the following java code including its output [5 Marks]
public class Tester
{
static void test(int[] a)
{
int[] b = new int[2];
a = b;
System.out.print(b.length);
System.out.print(a.length);
}
public static void main(String[] args)
{
int[] a = new int[5];
test(a);
System.out.print(a.length);
}}
c) Write a java class that reads and prints the values of the following array. [5 Marks]
Dam Lake Ocean borehole
d) Write a java class that performs the following tasks: [6 Marks]
i) Request user to enter customer details (e.g. customer name, name of the item
ordered and soon).

ii) stores the input an array

iii) Prints the results
QUESTION THREE
a) Write comments explaining the following java statements
Int Val, index = 2; (2 Marks)
Double gamma = 1.2, brightness; (2 Marks)
b) Categorize each of the following quantities by whether an int or double variable would
best to store it: (5 Marks)
i) Temperature in degrees Celsius
ii) The population of students
iii) A person’s age in years
iv) A person’s weight in pounds
v) A person’s height in meters
e) Describe the key word ‘import’ as used in java. Write a single line java code illustrating how
‘import’ can be used in java programming (3 Marks)
a) Explain the meaning of the following keywords
i. constructor (2 Marks)
ii. static method (2 Marks)
iii) object (2 Marks)
iv) break (2 Marks)
QUESTION FOUR
a) Write a java class that performs the following tasks (8 Marks)
i) Requests user to enter Marks for the following assignments
assignment1,assigment2
ii) Compute the sum and average of the two assignments
iii) Determines whether the Pass mark of 5 has been reached given that each
assignment is marked out of 5 Marks.
iv) Display results that include Marks entered for each assignment and whether it is a
pass or fail.
b) Write a java class that named booking that Prompt the a user to enter ticket details such
as idno, name, destination and then display all the values entered by the user (6 Marks).
c) Briefly explain the following java code (4 Marks)
public class numbers
{
Public static void main (String[] args)
{
int number;
number = 2 + 3 * 4;
System.out.println(number – 1); System.out.println(2 * number);
}
}
d) Briefly explain the following java code (2 Marks)
switch (day)
{
case 1:
System.out.println (“sunday ” );
break;
case 2:
System.out.println (“Tuesday ” );
break;
case 3:
System.out.println (“Wednesday ” );
break;
default : System.out.println (“unknown ” );
break;
}
QUESTION FIVE
a) Distinguish between over ridding and overloading as used in objected oriented programming
languages such as java. Give an example java code implementing for each case (6 Marks).
b) Describe the term ‘polymorphism’ as used in java programming language (2 Marks)
c) Briefly explain the meaning of the term ‘interface’ as used in java programming (2 Marks)
d) Define the term ‘multiple inheritance’. write a java code that demonstrates how it can be
implemented . (4 Marks)
e) Consider the following java code instructions and explain the purpose of the single line statements
appearing in bold. (4 Marks)
private static void createAndShowGUI()
{
JFrame frame = new JFrame(“Hi..”);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel(” Welcome to KCA University”);
frame.getContentPane().add(label);
frame.pack();
frame.setVisible(true);
}
d) Briefly explain importance of using ‘LayoutManager’ when developing programs using swing
with graphical interface. (2 Marks)

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

Written by