DIT410  JAVA PROGRAMMING.

UNIVERSITY EXAMINATIONS: 2015/2016
EXAMINATION FOR THE DIPLOMA IN INFORMATION TECHNOLGY
DIT410 JAVA PROGRAMMING
DATE: AUGUST 2016 TIME: 1½HOURS
INSTRUCTIONS: Answer Any THREE Questions.

QUESTION ONE
a) Determine the output of the following code snippet. [3 Marks]
int i;
int seed = 2*(4/5);
for(i=1; i<=3; i+=2)
seed += i;
System.out.println(seed);
b) Differentiate between Instance variables, Class variables and Local variables [3 Marks]
c) Describe Six (6) Java features. [6 Marks]
d) What is the difference between a break statement and a continue statement? [4 Marks]
e) Classes Car and Bus are children of the TransportVehicle class. Assuming the parent class to be
abstract, write the class declarations of the 3 classes. The class TransportVehicle is public as well.
Assuming that all the 3 classes are in the same Java file, what will be the name of that file?
[4 Marks]
QUESTION TWO
a) Write a Program to calculate charges for sending particles when the charges are as follows
For the first 1KG Ksh15.00 , For additional weight , for every 500gm or fraction thereof: Ksh
8.00 [6 Marks]
b) Differentiate between the following types of errors that can take place during the execution of a
program [3 Marks]
i. Syntax Error
ii. Run-time Error
iii. Logical Error
c) Differentiate between Boolean Literals and Character Literals (4 Marks)
d) Differentiate between a Superclass and a Subclass. (4 Marks)
e) Using sample codes explain the difference between method overloading and method overriding
[3 Marks]
QUESTION THREE
a) Write Java code for a program to compute the sum of the first 100 positive integers 1, 2… 100
[4 Marks]
b) Define the term access modifier. Explain the basic class access modifiers that can be
implemented in any java program [5 Marks]
c) State and resolve the error with the following program code [4 Marks]
int product = 0;
while (product < 500000){
product = product * 5;
}
d) Rewrite the following while loop as do-while loops [3 Marks]
int count = 0, sum = 0;
while (count < 10){
sum += count;
count++;
}
Write a java program to find the greatest number out of any given three. [4 Marks]
QUESTION FOUR
a) Type conversion is assign a value of one type to a variable of another type.Explain using code
samples two ways of type conversion: [6 Marks]
b) A cloth showroom has announced the following festival discounts on the purchase of items,
based on the total cost of the items purchased:- Total cost Discount (in Percentage)
Total cost Discount (in Percentage)
Less than Ksh. 2000 5%
Ksh. 2001 to Ksh. 5000 25%
Ksh. 5001 to Ksh. l0000 35%
Above Ksh. 10000 50%
Write a program to input the total cost and to compute and display the amount to be paid by the
customer after availing the discount.
[10 Marks]
c) Discuss the following elements of OOP [4 Marks]
i. Encapsulation
ii. Information Hiding
iii. Inheritance
iv. Polymorphism
QUESTION FIVE
a) What will be the output of the following program segment [4 Marks]
i. int a= 5, b = 2,c;
if (a>b || a ! = b)
c = ++a+–b;
System.out.print(c+ “ ”+a+ “ ”+b);
ii. int a = 0;
if(a>0 && a<20)
a++;
else a– ;
System.out.println(a);
b) Define between java application and an applet. [4 Marks]
c) Define what is an exception and what is exception handling [ 5 Marks]
4
d) Explain the meaning of the following escape sequences [4 Marks]
i. \n
ii. \t
iii. \b
iv. \
e) Using an example Explain what you understand by signature of a function [3 Marks]

 

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

Written by