BIT2204A  JAVA PROGRAMMING.

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

QUESTION ONE
a) State and explain three types of scope qualifiers that are used in java programming
(3 Marks)
b) Describe the characteristics of the following methods and write a sample java for each
case (4 Marks)
i. Non- static method
ii. Static method
iii. Getter method
iv. Modifier method
c) Describe the difference between Do-while loop and while loop. Write a sample code
for each case (4 Marks).
d) Write a Java class that implements the following algorithm (5 Marks)
e) Briefly describe the meaning of the following concepts as used in Java programming
1. Start
2. Input/read Deposit amount
3. Input/read Years
4. Input/read Rate
5. Interest=Amount*Years*Rate/100
6. Print Interest
7. Stop
(3 Marks)
i. Interface
ii. Abstract class
iii. adapter class
f) Describe the difference between continue and break statement (2 Marks)
g) Write a Java class that calculate the area and circumference of a circle. The class
should have at least two methods (6 Marks)
h) Write a Java class that calculate the sum and the product of two numbers. 3 Marks)
QUESTION TWO
a) Write a Java class that use at least two methods to calculate and prints the area and
perimeter of a rectangle (6 Marks)
b) Write a Java class that swaps values of two variables (4 Marks)
c) The Euclidean algorithm is based on the principle that the greatest common divisor of
two numbers does not change if the larger number is replaced by its difference with
the smaller number. For example, 21 is the GCD of 252 and 105 (as 252 = 21 × 12
and 105 = 21 × 5), and the same number 21 is also the GCD of 105 and 252 − 105 =
147. Since this replacement reduces the larger of the two numbers, repeating this
process gives successively smaller pairs of numbers until the two numbers become
equal. When that occurs, they are the GCD of the original two numbers. By reversing
the steps, the GCD can be expressed as a sum of the two original numbers each
multiplied by a positive or negative integer, e.g., 21 = 5 × 105 + (−2) × 252. The fact
that the GCD can always be expressed in this way is known as Bézout’s identity.”
Write a Java program to prove that Euclid’s algorithm computes the greatest common
divisor of two positive given integers (10 Marks)
QUESTION THREE
a) Write a Java class that compare values of two variables and print the results.
(5 Marks)
b) Write a java program that implements the following flow chart (5 Marks)


c) Suppose you create an interface that defines relationships between two objects
according to the “natural order” of the objects as follows:
public interface Relation {
public boolean isGreater(Object a, Object b);
public boolean isLess( Object a, Object b);
public boolean isEqual( Object a, Object b); }
Create a class that implement the above interface and its methods. (10 Marks)
QUESTION FOUR
a) Write a Java program to create a two-dimension array (m x m) A[][] such that A[i][j]
is true if I and j are prime and have no common factors, otherwise A[i][j] becomes
false. (8 Marks)
b) Given the following superclass
public class Person
{ public String getName(){
System.out.println(
“Parent:
getName”); return
name;
}
}
write a code to override, the getName method in the subclass Student (6 Marks)
c) using an appropriate example of a program explain how method overloading is used to
facilitate polymorphism (6 Marks)
QUESTION FIVE
a) Write a Java method to find all twin prime numbers less than 100 (5 Marks)
b) Write a Java program to sort an array of positive integers of a given array, in the sorted
array the value of the first element should be maximum, second value should be
minimum value, third should be second maximum, fourth second be second minimum
and so on. (5 Marks)
c) Write a Java program which accepts students name, id, and Marks and display the
highest score and the lowest score. (5 Marks)
d) Write a Java program that accepts six numbers as input and sorts them in descending order.
(5 Marks)

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

Written by