UNIVERSITY EXAMINATIONS: 2017/2018
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/BBIT 310/BAC 2201: JAVA PROGRAMMING
FULL TIME/PART TIME/DISTANCE LEARNING
DATE: JULY/AUGUST, 2018 TIME: 2 HOURS
INSTRUCTIONS: Answer Question One & ANY OTHER TWO questions.
QUESTION ONE
a) Explain the two types of errors encountered in java 4 Marks
b) Explain the five operators found in java 5 Marks
c) Using a flowchart explain the phrase decision control structures 5 Marks
d) Write a Java program that determines a student’s grade. 8 Marks
The program will read three types of scores(quiz, mid-term, and final scores) and determine
the grade based on the following rules:
-if the average score >=90% =>grade=A
-if the average score >= 70% and <90% => grade=B
-if the average score>=50% and <70% =>grade=C
-if the average score<50% =>grade=F
e) Explain the properties of a constructor 5 Marks
f) Outline three characteristics of java methods 3 Marks
QUESTION TWO
a) What is wrong with the following interface? (2 Marks)
public interface SomethingIsWrong {
void aMethod(int aValue) {
System.out.println(“Hi Mom”);
}
}
b) Fix the interface in Question 2a. (3 Marks)
c) Is the following interface valid? (2 Marks)
public interface Marker {
}
d) Which should you use, abstract classes or interfaces? discuss (6 Marks)
e) Write a Java program to reverse an array of integer values (7 Marks)
QUESTION THREE
a) Write a Java method to compute the future investment value at a given interest rate
for a specified number of years (8 Marks)
Sample data (Monthly compounded) and Output:
Input the investment amount: 1000
Input the rate of interest: 10
Input number of years: 5
Expected Output:
Years FutureValue
1 1104.71
2 1220.39
3 1348.18
4 1489.35
5 1645.31
b) Explain how Overriding and Hiding Methods are implemented (6 Marks)
c) Given the following class, called NumberHolder, write some code that creates an
instance of the class, initializes its two member variables, and then displays the value
of each member variable. (6 Marks)
public class NumberHolder {
public int anInt;
public float aFloat;
}
QUESTION FOUR
a) Briefly explain the following terms in the context Java programming. Write a sample
java code statement for each case
i) Concatenating operator (2 Marks)
ii) Array (2 Marks)
iii) Class (2 Marks)
iv) method (2Marks)
b) State and explain four features of java programming language (4 Marks)
c) Write a java class named Items_discount that request the user to enter the cost of at
least two item and computes discount to be awarded. The discount is set 8% of all
purchased items (4 Marks).
d) Briefly explain the purpose of using a constructor () method as used in java
programming (2 Marks)
e) Write a java class that calculates perimeter of a rectangle and print results (2 Marks)
QUESTION FIVE
a) Describe the importance of java compiler in the context of java programming
(2 Marks)
b) Describe the following java programming terms. Write java sample code that
demonstrate implementation of each term (6 Marks)
i) Repetition structure
ii) main () method
iii) Decision structure
c) Briefly explain for-loop in the context of java programming. Write a sample java
programming code that demonstrates its usage (4 Marks)
d) Write a well commented java class that prompts the user to enter two numbers and
determines which among the two numbers is larger before printing it. (4 Marks).
e) Describe the difference between do-while loop and while loop. Write a sample code
for each loop to illustrate your answer (4 Marks).