0% found this document useful (0 votes)
66 views

Exam Questions Set 1 CSC2106 Object-Oriented Design & Programming

Exam questions CSC2106 Object-Oriented Design & Programming at Catholic University Of Cameroon Bamenda

Uploaded by

Djamen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Exam Questions Set 1 CSC2106 Object-Oriented Design & Programming

Exam questions CSC2106 Object-Oriented Design & Programming at Catholic University Of Cameroon Bamenda

Uploaded by

Djamen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

CATHOLIC UNIVERSITY OF CAMEROON (CATUC), BAMENDA

P.O. Box 782 Bamenda, Cameroon

FIRST SEMESTER EXAMINATION 2023/2024 SESSION

FACULTY OF SCIENCE DEPARTMENT: Computer Science


LECTURER: DJAMEN NYONKEU Gildas
COURSE TITLE: Object-Oriented Design & Programming
COURSE CODE : CSC2106 CREDIT VALUE: 6 DURATION : 3h

INSTRUCTIONS: Answer all questions

Section - A (10 pts)


(Very Short Answer Questions)
(i) How does JAVA achieve platform independence?
(ii) What are the commands used to compile and run the JAVA Programs.
(iii) Determine the value of each of the following logical expressions if a = 5, b = 10 and c =
–6
a) a>b && a<c
b) a<b && a>c
c) a==c|| b>a
d) b>15 && c<0 || a>0
(iv) Explain any three string functions used in JAVA.
(v) Explain the difference between do-while statement and while statement.
(vi) Define an abstract class.
(v) What is the Java virtual machine (JVM)?
Section B: (30 pts)
1. (5 pts) What are the values of the following variables?
(a) double var1 = 10 / 3;
(b) int var2 = (int) (2.5 * 2.6);
(c) boolean var3 = !(3 > 3);
(d) boolean var4 = (121 % 11 == 0) || (5 == 5);
(e)int var5 = 11 % 3;
2. (3 points) Declare a variable to hold the amount of money in your bank account and
initialize it to 245.25. Name your Java variable in a meaningful way so that any programmer
would know what value it holds. Your variable name should be at least two words.
3. (3 points) Give the return type and value of the following method calls on str (defined in
the above question).
(a) str.length()
(b) str.equalsIgnoreCase("HOW ARE YOU")
(c) str.indexOf("ou")
(d) str.lastIndexOf(" ")
(e) str.charAt(6)
(f) str.substring(1, 6)
4. (3 pts) Write the output of test(1), test(3) and test(5).
public void test(int k) {
String t = "The quick brown fox jumps over the lazy dog";
for (int i = 0; i < k; i++) {
t = t.substring(t.indexOf(" ") + 1);
}
System.out.println(t.substring(0, t.indexOf(" ")));
}
5. (3 points) What are uses of final keyword with variable, method and class?
Give an example for each.
6. (1 pts) What the difference between usage of throws and throw keyword?
7.(2 pts) Identify the correct output for the following program fragments. Give the reason.
i.
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ee)
{
System.out.println(" Arithmetic Exception");
}
System.out.println("Finished");
a) Exception
b) Arithmetic Exception
c) Compilation fails
d) Finished
ii.
public class FinalBlock {
public static void main(String[] a){
try{
int x = 16/2;
}
catch(Exception ex){
System.out.println("A");
}
finally {
System.out.println("B");
}
try{
int x = 16/0;
}
catch(Exception ex){
System.out.println("C"); }
finally {
System.out.println("D"); }
}
}
8. ( 2 pts) Marks Obtained:
Identify and explain what are OOP Principles used in the following program.
abstract public class Animal {
abstract public void MakeVoice();
}
public class Cat extends Animal {
int LegsNumbers;
public void MakeVoice() {
System.out.println("Meow!");
}
}
public class Dog extends Animal {
String Color;
public void MakeVoice() {
System.out.println("Woof!");
}

public void MakeVoice(String c) {


System.out.println("Woooooooooof!"+ c);
}
}
9) Inheritance (3 pts)
Consider the following code.
class A {
private int x;
public A(int x) {
this.x= x;
}
public void m() {
System.out.println(x-1);
}
}
class B extends A{
private int y;
public B(int y) {
super(y-1);
this.y= y;
}
public void m() {
System.out.println(y+1);
}
}
(i) 1 point What is printed to the console by (new A(3)).m()?
(ii) 1 point What is printed to the console by (new B(3)).m()?
(iii) 1 point What is printed to the console by ((A)(new B(3))).m()?
10. (6 pts )Write a Swing application called SwingAdder as shown. The "ADD" button adds
the two integers and display the result. The "CLEAR" button shall clear all the text fields.

Hints: Set the content-pane to 4x2 GridLayout. The components are added from left-to-right,
top-to-bottom.
Section C: MySQL connection and SWING
(6 pts) To connect to mysql database using java programming, we must include a library.
What is the name of the library and explain how you include it in your project.

2. Describe the parameters of the following function:


DriverManager.getConnection("jdbc:mysql://localhost:3306/ict","root","root")
3. What is the meaning of the following instruction :
ResultSet rs=stmt.executeQuery("select * from employee");
4. From the above source code what is the name of the database and the table it contains?
5. What is the meaning of the following code? public class Authentification extends JFrame
implements ActionListener {
6. Write a java code to display a login form.
Section D (13 marks)
Consider the following class hierarchy where Class Car is the supper class and the classes
ClassicCar and SportCar are two subclasses derived from Car.
Class CarExhibition contains a filed of type ArrayList that stores objects of type Car.

(a) Class Car is an abstract class. Explain the role of an abstract class. [1 marks]
(b) Write a Java version of class Car assuming it has this constructor:
public Car(double price, int year)
and that the method calculateSalePrice ( ) is abstract. [3 marks]
(c) Write a Java version of class ClassicCar assuming it has this constructor:
public ClassicCar (double price, int year) [2 marks]
and that the method calculateSalePrice ( ) returns 10,000 as the sale price of the car.

d) Write a Java version of class SportCar assuming it has this constructor:


public SportCar(double price, int year) [3 marks]
and that the method calculateSalePrice ( ) calculates the sale price of the car as follow:
if year > 2000 then the sale price is 0.75 * its original price; if year > 1995 then the sale
price
is 0.5 * its original price; otherwise the sale price is 0.25 * its original price
e) Write a Java version of class CarExhibition assuming it has this constructor:
public CarExhibition( ) [4 marks]
where CarExhibition has cars of different types stored in an arraylist and getTotalPrice
method that
returns the total prices of all cars in the exhibition.

You might also like