BIT 2204A JAVA PROGRAMMING.

UNIVERSITY EXAMINATIONS: 2018/2019
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
BIT 2204A: JAVA PROGRAMMING
FULL TIME/PART TIME/DISTANCE LEARNING
DATE: DECEMBER, 2018 TIME: 2 HOURS
INSTRUCTIONS: Answer Question One & ANY OTHER TWO questions.

QUESTION ONE
a) Briefly describe three types of programming errors that are encountered in java programming.
write a java code example for each case (6 Marks)
b) Briefly explain the following terms in the context Java programming. Write a sample java code
statement for each case
i) Variable (2 Marks)
ii) Identifier (2 Marks)
iii) Assignment operator (2 Marks)
iv) concatenating operator (2 Marks)
c). Describe three properties of a ‘constructor’ as used Java programming. Write a sample code that
implements a constructor (4 Marks)
d) Discuss four features of Java programming language. (4 Marks)
e) Write a well commented java program that prompts the user to enter two numbers, evaluates which
among the two is higher and prints the results.
(4 Marks)
f) Describe the meaning of the term inheritance and write a sample code that demonstrates how it is
implemented in java programming (4 Marks)
QUESTION TWO
The following method was written to determine whether its String parameter reads
identically left-to-right and right-to-left (the so called palindrome).
boolean isPalindrome(String s) {
int i = 0, j = s.length() – 1;
while (i != j && s.charAt(i) == s.charAt(j)) {
i++;
j–;
}
return (i == j);
}
This method compiles fine, yet unfortunately, the code contains a logic error, which
may result in a run-time error, or wrong output.
a) Find the error and explain what problem it will cause (2 Marks)
b) Fix the error (write the correct statements) (3 Marks)
c) Write an alternative, recursive implementation (6 Marks)
d) What are three benefits which exceptions bring to Object-Oriented Programming?
(3 Marks)
e) Write a program called ExtractDigits to extract each digit from an int, in the reverse order.
For example, if the int is 15423, the output shall be “3 2 4 5 1”, with a space separating the
digits. (6 Marks)
QUESTION THREE
a) Write a program called Bin2Dec to convert an input binary string into its equivalent decimal
number (3 Marks)
b) Write a program called GradesAverage, which prompts user for the number of students,
reads it from the keyboard, and saves it in an int variable called numStudents. It then prompts
user for the grades of each of the students and saves them in an int array called grades. Your
program shall check that the grade is between 0 and 100.
(6 Marks)
c) Write a method called printArray(), which takes an int array and print its contents in the form
of {a1, a2, …, an} (4 Marks)
d) Differentiate between the following (4 Marks)
i) Abstract class and Interface
ii) Constructor and a method
e) Using an example describe the concept of method overloading (3 Marks)
QUESTION FOUR
a). Write a java program for computing circumference and area of circle. The program should contain
the following features (6 Marks)
i. Object
ii. More than one methods
b) Create class named House_items that prompts the user to enter three names of three items found
in a house, e.g. chair, table, utensils etc a. The features of the program should include the following:
i. Array for storing items entered by the user
ii. For-loop for accessing the array and prints all the items entered by the user
(5 Marks)

(c) Differentiate between private and public class. Elaborate with suitable example (3 Marks)
(d) describe the meaning of the term ‘bytecode’ in the context of java programming (2 Marks)
(e) 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
QUESTION FIVE
a) describe the difference between the following control structures and write a sample java code to
illustrate your answer.
i) Do-while loop and while loop (4 Marks)
ii) If structure and If/else structure (4 Marks)
b) Create a class named eggs. Its main() method holds an integer variable named numberofeggs to
which you will store a value. Create a method to which you pass numberofeggs. The method displays
the eggs in dozens. For example, 25 eggs is 2 dozens and 1 left over. (6 Marks)
c) Write a class named employee, that request an employee to enter the number of hours worked
computes total payment using the following formula : (6 Marks)

Totalpayment=hoursworked*1000.
The program should displays results. For example
Hours worked: 3
Totalpayment : 3000

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

Written by