BIT2204A  JAVA PROGRAMMING2 . KCA Past Paper

UNIVERSITY EXAMINATIONS: 2016/2017
EXAMINATION FOR THE DEGREE OF BACHELOR OF SCIENCE
IN INFORMATION TECHNOLOGY/BACHELOR OF BUSINESS
INFORMATION TECHNOLOGY/BACHELOR OFINFORMATION
COMMUNICATION TECHNOLOGY/BACHELOR OF SCIENCE
APPLIED COMPUTING
BIT2204A JAVA PROGRAMMING
FULL TIME/PART TIME/DISTANCE LEARNING
DATE: AUGUST, 2017 TIME: 2 HOURS
INSTRUCTIONS: Answer Question One & ANY OTHER TWO questions.

QUESTION ONE
a) Explain the two types of errors encountered in java (4 Marks)
b) Explain the five operators found in java (5 Marks)
c) Using a flowchart explain the term decision control structures (5 Marks)
d) Write a Java program that determines a student’s grade. (8 Marks)
The program will read three types of scores(quiz, mid-term, and final scores) and determine the grade based
on the following rules:
-if the average score >=90% =>grade=A
-if the average score >= 70% and <90% => grade=B
-if the average score>=50% and <70% =>grade=C
-if the average score<50% =>grade=F
e) Explain the properties of a constructor (5 Marks)
f) Outline three characteristics of java methods (3 Marks)
QUESTION TWO
(a) Describe the importance of java virtual machine (JVM) (2 Marks)
(b) Describe the following java programming terms. Write java sample code that demonstrate
implementation of each term (6 Marks)
(i) Constructor
(ii) Inheritance
(iii) Object
(c) Briefly explain switch selection structure in the context of java programming. Write a sample
java programming code that demonstrates its usage (5 Marks)
(d) Write a well commented java class that prompts the user to enter two numbers, computes the
sum, average and prints the results. (4 Marks)
(e) Describe the difference between static and non-static methods. Write a sample code to illustrate
your answer (4 Marks)
QUESTION THREE
a) Write a Java method to compute the future investment value at a given interest rate for a
specified number of years (8 Marks)
Sample data (Monthly compounded) and Output:
Input the investment amount: 1000
Input the rate of interest: 10
Input number of years: 5
Expected Output:
Years FutureValue
1 1104.71
2 1220.39
3 1348.18
4 1489.35
5 1645.31
b) Explain how Overriding and Hiding Methods are implemented (6 Marks)
c) Given the following class, called NumberHolder, write some code that creates an
instance of the class, initializes its two member variables, and then displays the value of
each member variable. (6 Marks)
public class NumberHolder {
public int anInt;
public float aFloat;
}
QUESTION FOUR
(a) Briefly explain the difference between the following concepts as used in java programming
(i) Java compiler and java interpreter (2 Marks).
(ii) Increment and decrement operators (2 Marks).
(iii) Getter () and Setter () methods (2 Marks).
(b) Write a program that performs the following tasks (4 Marks)
1. Declare variables for storing Marks of any three subjects
2. Prompts the user to enter total KCSE Marks.
3. Utilize decision structure to determine the grade (e.g. A,B …)
4. Prints the grade
(c) Write a java program that performs the following tasks: (6 Marks)
1. Prompts the user to enter the number of registered course units.
2. Use a certain repetition structure for requesting the user to enter each of the registered units
3. Prints all subjects entered by the user.
(d) Write a program called CircleComputation, which prompts user for a radius (of double)
and compute the area and perimeter of a circle. The output shall look like: (4 Marks)
Enter the radius: 1.2
The area is 4.5239
The perimeter is 7.5
QUESTION FIVE
(a) Describe the meaning of the term ‘Exception’ in the context of java programming
(2 Marks)
(b) Briefly explain the difference between checked and unchecked exceptions in the context
of java programming. Give one example for each case
(3 Marks)
(c) Briefly explain the meaning of the following terms as used in java programming. Write a
sample java code to illustrate each case
(i) Throw and throws (4 Marks)
(ii) Try and Catch (4 Marks)
(d) Consider the following java code instructions and explain the purpose of the following
java programming statements. (4 Marks)
private static void createAndShowGUI()
{
JFrame frame = new JFrame(“Java Programming.”);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel(” Topics”);
frame.getContentPane().add(label);
frame.pack();
frame.setVisible(true);
}
(e) Briefly explain importance of using ‘Layout classes’ when developing programs using
swing with graphical interface. Write a sample java code that illustrates implementation of
one layout class. (3 Marks)

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

Written by