UNIVERSITY EXAMINATIONS: 2013/2014
ORDINARY EXAMINATION FOR THE BACHELOR OF SCIENCE
IN INFORMATION TECHNOLOGY
BIT 3209 MOBILE PROGRAMMING
DATE: APRIL, 2014 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and any other TWO
QUESTION ONE
a) Illustrate android architecture listing four layers and at least two components in
each layer (10 Marks)
b) Illustrate using a diagram state transition of an activity (10 Marks)
c) Write an Android that allows a user to input the coefficients of a line equation and
returns the triangle area formed by the line, x-axis, and y-axis.
A possible run may look like:
Enter the line ax + by = c: 12 5 60
The triangle area is 30.000000.
Enter the line ax + by = c: 3 4 12
The triangle area is 6.000000.
(10 Marks)
QUESTION TWO
a) Write an Android program to guess a random number between 2 to 12.
A possible run may look like:
Guess a number between 2 and 12: 8
Too high.
Try again: 4
Too low.
Try again: 6
Too high.
Try again: 5
Excellent! You guessed the correct number!
Hint:
import java.util.Random;
Ramdon r;
r.nextInt(n);
(20 Marks)
QUESTION THREE
a) Define and explain the relationship between default parameters and overloading.
(4 Marks)
b) What is the difference between pass-by-reference and pass-by-value-result?
(2 Marks)
c) What is an activation record? (2 Marks)
d) What is an exception handler? Use an example to explain your answer (4 Marks)
e) What is information hiding and how is it implemented? (4 Marks)
f) Write a function named middle with three parameters of type int. The function
should return the middle number among its three parameters, in order of size. For
example, middle(3,17,12) would have the value 12; middle(737,-33,1266) would
have the value 737; and middle(42,42,42) would have the value 42. (4 Marks)
QUESTION FOUR
a) Suppose that income tax is determined as follows: If income is less than $10,000,
then there is no tax. For incomes between $10,000 and $30,000, the tax is 0.15
times (income – 10000). For incomes greater than $30,000, the tax is 3000 plus
0.3 times (income – 30000). Write a program segment that inputs the amount of
income from the user and prints out the income tax on that amount. You do not
have to write a complete program, but you should declare any variables that you
use. (10 Marks)
b) Write a complete function named pythagorus. It should have two parameters, x
and y, of type double. It should compute and return as its value: the square root of
(x2
+ y2
). (4 Marks)
c) Write a for statement that will compute the sum of the first 100 integers, that is,
1*1 + 2*2 + 3*3 + … + 100*100. You should not write a complete program, but
you should declare any variables that you use. (3 Marks)
d) Write a complete and syntactically correct program that outputs the following
message in the display window:
The even numbers between 2 and 98
and then outputs the specified even numbers using a while loop that will only
display 5 even numbers per line. (3 Marks)
QUESTION FIVE
a) Write a function that finds the sum of all the numbers in an array of int’s. The
function should be named arraySum. It should have two parameters of type int[]
for the array and int for size. It should return a value of type int. The value that is
returned should be obtained by adding up all the numbers in the array. (6 Marks)
b) Write a function moveToFront(char arr[], char c). Return true from the method if
the element is in the list and it has been moved to the front of the list otherwise,
return false if the element is not in the list. You may assume that if the element
exists in the list, it only exists once. (4 Marks)
c) Differentiate between the following terms
i) CLDC and CDC
ii) Canvas and Display
iii) J2ME and Android development platforms
(6 Marks)
d) Define and discuss MIDP (4 Marks)