UNIVERSITY EXAMINATIONS: 2017/2018
EXAMINATION FOR THE DEGREE OF BACHELOR OF SCIENCE IN
INFORMATION TECHNOLOGY
BIT2204A JAVA PROGRAMMING
FULL TIME/PART TIME/ DISTANCE LEARNING
DATE: APRIL, 2018 TIME: 2 HOURS
INSTRUCTIONS: Answer Question One & ANY OTHER TWO questions.
QUESTION ONE (Compulsory)
(a) Briefly explain the following terms in the context Java programming. Write a sample java code
statement for each case
i) array (2 Marks)
ii) method (2 Marks)
iii) Assignment (2 Marks)
iv) variable (2Marks)
(b) Briefly explain three features of Java programming language platform (3 Marks).
(c) Write java program that utilizes for-loop to print the following output. Write comments to
Explain your code (4 Marks)
Tom, kim,james,kamau
(d) Consider the following table:
State a java program that use Switch structure to print one of the above statements depending on the
selected day. Write comments to explain your code. (6 Marks)
day statement
Any other day “ Unknown day !”
(e) Write a sample java programming code that use else/if structure to print a certain age group
depending on the value of Age (5 Marks)
(f) Write a well commented java program that computes the sum, average and prints a pass if average
>=15 or fail if average <15 (4 Marks).
QUESTION TWO
(a). Write a Java class to print ‘Hello’ on screen and then print your name on a separate line as
follows: (3 Marks)
Hello
Michael Jones
(b)Write a Java program to print the result of the following operation. (3 Marks)
-5 + 8 * 6
(c) Write a Java class that takes two numbers as input and display the product of two numbers.
(3 Marks)
(d) Write a Java class that calculates area and perimeter of a circle. The class should have at least two
methods (6 Marks)
(e) Write a Java program to compare two numbers and prints the largest of the two.
(3 Marks)
(f) The purpose of the following components java platform
(i) Java virtual machine as used in java programming (1 Mark)
(ii) Java compiler (1 Mark)
QUESTION THREE
(a) Write java code statements that uses for -Loop to print the following five characters [4 Marks]
DJWLS
(b). Write a java class that calculates the area of a triangle and print results (Area=1/2*base*height)
(4 Marks)
(c). Write a java class that reads the elements of the following array known as numbers and prints
results (4 Marks)
numbers
40 10 25 36
(d) Explain the following Java programming statements (4 Marks)
(e) Briefly explain the purpose of the following escape statements in the context of java
programming. Write a sample java code that demonstrates their usage (4 Marks)
(i) return
(ii) Break
QUESTION FOUR
(a) Briefly explain the purpose of using interfaces in java programming (2 Marks)
(b). Write a java program for computing area of a square. (4 Marks)
(c) Create class named customers_names that prompts the user to enter three names of three
customers, puts them in an Array, utilize do – while loop to read the names in the array and prints all
the of them (5 Marks)
(d) Describe the meaning of the term ‘void’ in the context of java programming (2 Marks)
(f) Write while-loop structure using a well commented java programming code that can print the
following five numbers (5 Marks)
1,2,3,4,5
(g) Describe the advantage of using non-static methods in java programming (2 Marks)
QUESTION FIVE
(a) Explain the difference between increment and decrement operator. write a sample java code that
demonstrates application of each operator (4 Marks)
(c) Briefly explain the meaning of the term static method. Write a sample code to illustrate your
answer (2 Marks)
(d) Write a java program that computes the perimeter of a rectangle and displays results. The program
should have at least two methods (4 Marks)
(e) Write a java code statements that puts the following 5 numbers into an array known as Nums
(4 Marks)
57324
QUESTION FIVE
(a)Describe the difference between an object and a class .write java code to illustrate your
answer. (4 Marks).
(b). Explain the meaning of the following keywords. Write a sample java code that illustrates how
each keyword is implemented (4 Marks)
i. implements
ii. Extends
(c) Write a program that performs the following tasks [4 Marks]
1. Declare variables for storing Marks
2. Prompts the user to enter total KCSE Marks.
3. Utilize switch structure to determine the grade (e.g. A,B …)
4. Prints the grade
(d) Explain two types of stream classes and their importance in java programming [4 Marks]
(e) Briefly explain the purpose for each the following stream classes. [4 Marks]