UNIVERSITY OF MINES AND TECHNOLOGY, TARKWA
SECOND SEMESTER EXAMINATIONS, APRIL/MAY 2019
COURSE NO: CE 274
COURSE NAME: PROGRAMMING WITH JAVA
CLASS: CE II TIME: 2 HRS
Name: __________________________________________ Index Number: _______________
Attempt ALL Questions
1. Define a variable in programming and list the three types of variables in Java. [2.5 marks]
2. Explain the concept of type casting in programming and state the differences between
widening type and narrowing type casting. [2 marks]
3. Define an exception in programming and list three instances when it is needed. [2.5 marks]
4. Briefly explain the functions of the following blocks in exception handling: [1 mark each]
a) Try block b) Catch block c) Finally block
5. List three differences between the Scanner and the BufferedReader. [3 marks]
6. State an advantage and a disadvantage each of the compiler and interpreter in programming
[2 marks]
7. Given the expression (((x<=49)^(x >= 30))^(x<99) )&&((x>=20)||(x>=45)),
what is the value of the expression if: [0.5 marks each]
a. x = 50
b. x = 48
c. x = 20
d. x = 31
e. x = 100
f. x = 60
Page 1 of 3
8. Identify and correct the errors in the following codes: [2 marks each]
a.
b.
9. Rewrite the following switch statements into if-else statements. [3 marks]
int x; int y;
int z = (x + 2*y);
switch (z) {
case 4: y-= 2x^y;
break;
case 5: y+= x^y;
break;
case 6: y+= x + 3%y;
break;
default: y+= x-y;
}
10. List three visibility modifiers for classes and explain how they affect methods and data fields
in classes with the mentioned visibility modifiers. [3 marks]
11. Briefly explain the differences between the following:
a. A single dimensional Array and an ArrayList [2 marks]
b. A HashSet and a HashMap [2 marks]
12. Mary, a novice in Java programming wants to use a multidimensional array in storing the
names and marks of a students in the code shown below.
public class storeStdMarks {
Page 2 of 3
public static void main (String[] Exams) {
String dimArray [] = new Int [3][2];
dimArray = [0][0] = John Annan;
dimArray = [0][1] = 86;
dimArray = [1][2] = Theresa Opoku;
dimArray = [1][3] = 83;
dimArray = [1][4] = Titus Clinton;
dimArray = [1][5] = 79;
}
}
a. Identify and correct the errors in Mary’s code [3 marks]
b. Using a for-loop write a code for Mary who wants to print out only the marks of each
student in the console. [2 marks]
13. Write a loop that computes the sum of all numbers between 2 and 100 inclusive that are
whole number multiples of 5 or 7. [2 marks]
14. Write a conditional statement with three branches that sets y to: 2 if x is positive, -3 if x is
negative, and 0 if x is zero. [3 marks]
Examiner: Nofong
Page 3 of 3