BIT2204A  JAVA PROGRAMMINGa.

UNIVERSITY EXAMINATIONS: 2018/2019
EXAMINATION FOR BACHELOR OF SCIENCE IN INFORMATION
TECHNOLOGY/ BUSINESS INFORMATION TECHNOLOGY/
APPLIED COMPUTING
BIT 2204A: JAVA PROGRAMMING
FULLTIME/PARTIME/DISTANCE LEARNING
DATE: AUGUST, 2019 TIME: 2 HOURS
INSTRUCTIONS: Answer Question One and Any Other Two Questions

QUESTION ONE
a) Write two different Java statements where each statement adds 1 to integer variable x.
(2 Marks)
b) Write Java statements to accomplish each of the following tasks:
i) Assign the sum of x and y to z and increment the value of x by 1 after the calculation.
(2 Marks)
ii) Test if the value of the variable count is greater than 10. If it is, print “Count is greater
than 10”. (2 Marks)
c) Name FOUR (4) primitive types of data provided by the Java programming language.
(2 Marks)
d) Assume i=1, j=2, k=3, and m=2. What does each of the following statements print?
i) System.out.println(i >=1 && j<4); (1 Mark)
ii) System.out.println( !(k>m)); (1 Mark)
iii) System.out.println(m<=99 && k<m); (1 Mark)
iv) System.out.println(j>=i || k==m); (1 Mark)
e) Write a catch block to demonstrate exception handling when an array subscript is not
within the allowed range. (2 Marks)
f) Explain why the following two methods cannot coexist within a program:
int aMethod(int x);
void aMethod(int x);
(3 Marks)
g) Given String myName = “STACY”, write the method to perform the following tasks.
i) Convert myName to lower case. (1 Mark)
ii) Test if myName ends with “Y”; (1 Mark)
h) Define the term overloading. (2 Marks)
i) Write a Java program the asks a user to enter three digit number and the program reverses
and prints out the digits of the number reversed. (5 Marks)
j) Using some example code snippets, explain three looping constructs in Java. (5 Marks)
QUESTION TWO
a) Given String[] deptName = {“Accounting”, “Human Resources”, “Sales”};
i) Write a Java statement to print these department names using a for loop and the
length field. (3 Marks)
ii) Write a Java statement to print the length of the first string in the array. (2 Marks)
b) Rewrite the following program segment using the switch statement.
if(year ==1)
System.out.println(“Freshman”);
else if(year ==2)
System.out.println(“Sophomore”);
else if(year ==3)
System.out.println(“Junior”);
else if(year ==4)
System.out.println(“Senior”);
else System.out.println(“Invalid Year”);
(5 Marks)
c) Write a java method that prints out even numbers between the values a and b inclusive.
(10 Marks)
QUESTION THREE
a) Descibe the following terms as used in oop. (10 Marks)
i. Object
ii. Overloading
iii. Overwriting
iv. Encapsulation
v. inheritance
b) Using the Scanner, write a program that will ask the user to enter their name and
thereafter display the name on the screen with the preceeding string “Hello “
(10 Marks)
QUESTION FOUR
a) A monthly car insurance premium is $200 if the driver is aged 25 or younger, and $125 if
the driver is aged 26 or older. Write a program using the conditional operator for the
above statement. (3 Marks)


b) Another way to get input from the user is by using the JOptionPane class which is found
in the javax.swing package. Rewrite the program in question 3 above so as to produce the
following output: (7 Marks)
QUESTION FIVE
a) What is the output from the following Java program fragment? (4 Marks)
String S = “”; String T = “”;
int i = 4;
for (i = 1; i <= 3; i++);
S = S + “!”;
for (i = 1; i < 4; i++)
T = T + “*”;
System.out.print(S);
System.out.println(T);
b) Define recursion (2 Marks)
c) Write a recursive method to find the factorial of a number N. (5 Marks)
d) Write a recurive method that sums numbers in an array (10 Marks)

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

Written by