Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
21 views7 pages

Sectioll A: Answer ALL Questions in This Section. Section B: Answer Question 1 and ANY TWO (2) Questions From Section B

Uploaded by

Atta Junior
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views7 pages

Sectioll A: Answer ALL Questions in This Section. Section B: Answer Question 1 and ANY TWO (2) Questions From Section B

Uploaded by

Atta Junior
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

• III1

g
UNIVERSITY OF GHANA
(All rights reserved)

B.SC, FIRST SEMESTER UNIVERSITY EXAMINATIONS: 2017/2018

DEPARTMENT OF COMPUTER SCIENCE

CSIT 205: OBJECT-ORIENTED TECHNIQUES FOR I.T. PROBLEM SOLVING (3 CREDITS)

INSTRUCTIONS:

Sectioll A: Answer ALL questions in this section.

Section B: Answer Question 1 and ANY TWO (2) questions from section B.

TIME ALLOWED:
THREE (3) HOURS

SECTION A (30 MARKS)

1. Which of the following statements correctly describes an interface?


a). It's a concrete class.
b). It's a superclass.
c). It's a type of abstract class.
d). It's a subclass.

2. You would use the _ _ operator to create a single instance of a named class.
a). new.
b). dot.
c). equals.
d). <>.

3. An interface contains _ _ _ _ methods.


a). non-abstract.
b). implemented.
c). unimplemented.
d). abstract.

4. What will be the result of compiling the following code?


public class Test{

Examiner :Paul Nii Tackie Ammo" Page 1 of7


static int age = 8;
public static void main (String args []){
age = --age +1;
System.out.println(OOThe age is 00 + age);
}
}
a). Compiles and runs with no output.
b). Compiles and runs printing out "The age is 8".
c). Compiles and runs printing out "The age is 7".
d). Compiles and runs printing out "The age is 9".

5. What is the value ofy when the code below is executed?


int x = 4;
int y = (int)Math.ceil(x % 5 + x I 5.0);
a). 1
b). 6
c). 5
d). 4

6. What is the output of the following program?


public class Test
{
public static void maine String[] args )
{
private static final int value = 5;
float total;
total = value + value I 2;
System.out.println( total );
}
}
a). 7.5
b). 7.0
c). 5;0
d). None of the above

7. Consider the following program:


import my Library. *;
public class ShowSomeClass
{
II code for the class ...
}

What is the name of the java file containing this program?


a). myLibrary.java

Examiner :Paul Nii Tackie Ammah Page 2 of7


\ ,

• b). ShowSomeClass.java
c). ShowSomeClass
d). ShowSomeClass.class

8. What is the value of variable z after executing the following code?


intx= 5; inty= 5;
int z = 5;
if(x> 3) if(y > 4) if(z> 5) z += 1;
else z += 2;
elsez+=3;z+=4;

a). 9
b). 5
c). 11
d). 7

9. is one of the java features that enables java program to run anywhere anytime.
a). Object-Oriented
b). Multithreaded
c). Platform-Independent
d). Dynamic & Extensible

10. _ _ _ _ _ operators are used to construct mathematical expression as in algebra).


a). Relational
b). Mathematical
c). Arithmetic
d). Logical

11. Which of the following is not assignment operator?


a). +=
b). ==
c). %=
d). =

12. String class in encapsulated under which package?


a). javac.lang
b). javac.util
c). javac.io
d). javac.awt

13. Which of these keywords is used to prevent content ofa variable from being modified?
a) final
b} last
c) constant
d) static

Examiner :Paul Nii Tackie Ammah Page 3 of7


14. Command to execute a compiled Java program is _ _ _ _ _ _ __
c;::;:.
a). javac l
b). java ,
'--("

!
c). run
d). execute

15. The Java compiler


a). creates executable
b). translates Java source code to byte code
c). creates classes
d). produces Java Interpreter

16. What is the process of defining more than one method in a class differentiated by method
signature?
a) Function overriding
b) Function overloading
c) Function doubling
d) None of the mentioned

17. Which of the following is a method having same name as that of its class?
a) finalize
b) delete
c) class
d) constructor

18. Which method can be defined only once in a program?


a) main method
b) finalize method
c) static method
d) private method

19. Which of these selection statements test only for equality?


a) if
b) switch
c) if & switch
d) None of the mentioned

20. Which of these are selection statements in Java?


a) if0
b) forO
c) continue
d) break

21. Which of the following loops will execute the body of loop even when condition controlling
the loop is initially false?
a) do-while

Examiner :Paul Nii Tackie Ammah Page40f7 .


. '

• b) while
c) for
d) None of the mentioned

22. Which of these jump statements can skip processing remainder of code in its body for a
particular iteration?
a) break
b) return
c) exit
d) continue

23. Which of these statement is correct?


a) switch statement is more efficient than a set of nested ifs.
b) two case constants in the same switch can have identical values.
c) switch statement can only test for equality, whereas if statement can evaluate any type of
boolean expression.
d) it is possible to create a nested switch statements.

24. Translate this statement into Java: If the value of temperature is in between 20.0 and 40.0,
print "very cold".
a). if(!(temperature < 20.0 II temperature> 40.0» System.out.printIn("very cold");
b). if(20.0 <= temperature <= 40.0) System.out.println("very cold");
c). if(temperature >= 20.0 II temperature <= 40.0) System.out.println("very cold");
d). if(temperature >= 20.0 I temperature <= 40.0) System.out.println("very cold");

25. Which of the foHowing is a valid declaration of an object of class Box?


a) Box obj = new BoxO;
b) Box obj = new Box;
c) obj = new BoxO;
d) new Box obj;

26. What will be output using foHowing code block?


int[] a = {O,I,2,3,4,5,6,7,9,10,ll,12};
System.out.println(a.length);
a). 10
b). 11
c). 12
d). 13

27. What is the output ofthis program?


class Evaluate (
public static void main(String args[J)
{
int arr[] = new int[] {O, 1,2,3,4,5,6,7,8, 9};
int n = 6;
n = arr[arr[n] /2];

Examiner :Paul Nii Tackie Ammah Page 5 of7


System.out.printIn(arr[n] / 2);
}
}
a). 3
b). 0
c). 6
d). I

28. A constructor
a). must have the same name as the class it is declared within.
b). is used to create objects.
c). may be declared private
d). A and B

29. Which of the following is NOT a key component of object oriented programming?
a).
b).
Inheritance
Encapsulation
l
I
c). Polymorphism !
d). Parallelism

30. ____ Keyword is used to invoke the current object. .,·1


a). new
b). static
c). this
d). object

SECTIONB
Answer Question one (1) and any other two (2) questions.
"
QI.Explain briefly the following terms as related to object-oriented design in Java
1. Inheritance
Il. Polymorphism
Ill. Superclass
IV. Subclass
v. Abstract Class
VI. Constructors
Vll. Interface
Vlli. Method Overloading
IX. Method Overriding
x. Instantiation
Xl. Exceptions
XIl. Static Variable
Xlll. Access Modifiers
XIV. Casting
xv. Inunutable Object
[30 Marks]

Examiner :Paul Nii Tackie Ammah Page 6 of7



~

~
Q2.
a. Write a method that displays all the numbers from 10 to 1000 that are divisible by 5 and 6.
[5 Marks]
b. Assume an array with name myArray exists.
Write statements to do the following:
i. Copy elements of my Array variable into myNewArray variable where both
myNewArray and myArray have the same data type and size.
ii. Write a method that computes the sum of all elements in the myArray.
iii. Write a method that finds the minimum element in the myArray.
iv. Write a method that prints the elements stored in the odd indexes of the myArray.
v. Write a method that orders the elements in myArray in ascending order.

[IS Marks]

Q3.

a. Write a Java method that accepts an integer and returns all the prime numbers up to that
number in an array. [8 Marks]

b. Write a program that reads the balance and the annual percentage interest rate and
displays the interest for the next month using the following formula:
interest = balance • (annualinterestRate / 1200)

[12 Marks]

Q4. Write a class named QuadraticEquation for a quadratic equation. The class should contain:
i. Private data fields a, b, and c that represents three coefficients.
ii. A constructor for the arguments for a, b, and c.
iii. Three get methods for a, b, and c.
iv. A method named getDiscriminantO that returns the discriminant, which is b 2 _
4ac.

v. The methods named getRootlO and getRoot20 for returning two roots of the
equation

r, -
-b +
---~--~-
Vb 2 - 4ac
and r2 -
-b - Vb" - 4ac
2a 2a

[20 marks]

Examiner :Paul Nii Tackie Ammah Page 7 of7

You might also like