BIT 2204A  BBIT 310  BAC 2201  BSD 2107  BISF 2201 JAVA PROGRAMMING.

UNIVERSITY EXAMINATIONS: 2020/2021
EXAMINATION FOR DEGREE IN BACHELOR OF SCIENCE IN
INFORMATION TECHNOLOGY/ BUSINESS I.T/APPLIED
COMPUTING/ SOFTWARE DEV./INFO. SECURITY& FORENSICS
BIT 2204A/ BBIT 310 /BAC 2201/ BSD 2107/BISF 2201:
JAVA PROGRAMMING
FULL TIME/ PART TIME/DISTANCE LEARNING
ORDINARY EXAMINATIONS
DATE: DECEMBER, 2021 TIME: 2 HOURS
INSTRUCTIONS: Answer Question One COMPULSORY and ANY OTHER TWO

questions
QUESTION ONE -20 MARKS
a). Write the expression shown below as a Java expression [3 marks]

b). Give the uses of each of the following keywords in java. [2 marks]
i) this
ii) super
c). A fellow programmer has declared a class called Employee with the following members:
Employee ID, Employee Name, Basic Salary, Allowances and Net Salary.
i.) Write code for a member function called get_input that will be used for data input
[3 marks]
ii.) Write code for a member function called calculate that will be used to calculate net salary
as the sum of basic salary and allowances. [2 marks]
iii.)Write code for a constructor that will assign values to the variables in the Employee class.
[3 marks]
iv.)Write code for the default constructor. [3 marks]
d). Rewrite the following code segment using while loops: [4 marks]
for(x = 0 ;x <= 5;x++)
{
for( y = 5; y >= 0; – –y)
{
product = (x + 1) * (y + 2);
System.out.println(product);
}
}
QUESTION TWO – 15 MARKS
a). List the four integer types that can be used in Java. [4 marks]
b). Rewrite the code below using the switch statement.
if (oper = = ‘+’)
ans = a + b;
else if (oper = = ‘-’)
ans = a – b;
else if (oper = = ‘*’)
ans = a * b;
else if (oper = = ‘/’)
ans = a / b;
else
System.out.println(“Invalid Operator”); [4 marks]
c). Using a line of code, illustrate how you would declare PI as a constant. [2 marks]
Write a program that accepts a list of integers and computes their sum. The program should allow
the user to enter any number of integers but an input of zero should terminate the list. For example,
if the user enters 2 5 6 12 8 2 0 the sum should be 35. If he/she enters 2 4 5 0 the sum should be
11 and if he enters 5 4 6 0 12 43 2 the sum should 15 i.e. only numbers before zero are summed.
The rest are ignored and the program terminated. [5 marks]
QUESTION THREE – 15 MARKS
a) Differentiate between and an abstract and a concrete method in Java [4 marks]
b) Class members can either be instance or static. Differentiate between the two with examples
in java [6 marks]
c) Write codes to illustrate method overloading in Java [5 marks]
QUESTION FOUR – 15 MARKS
You have been asked to implement a user-interface component ButtonCanvas which is both a
button that can be clicked by the user and a canvas which the user can draw on. Your existing code
contains a Button class and a Canvas class. Both of these extend GuiComponent.
a). ButtonCanvas could be built using multiple inheritance. What does this mean in this context?
[3 marks]
b). Give two reasons why this might be desirable. [3 marks]
c). Give two complexities that arise in this case. [3 marks]
d). Java interfaces originally contained only abstract methods and static final fields. How did this
restriction avoid the complexities of extending multiple classes? [3 marks]
e). Recent versions of Java added default methods to interfaces. What is the impact of this with
respect to multiple inheritance? [3 marks]

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

Written by