OOP Final 2
OOP Final 2
School of Engineering
Department of Computing
Object-Oriented Programming with Java (EEng 2301):
Final Exam (50%)
Student Information:
Name: ____________________
ID NO: ________________
Department: _______________
Group: _________________
Mark
1
Part I : Short answer (6 points)
1. What is difference between a class and Interface (2 points)
2. Compare and contrast between declaring a instance variable as protected compare to private access
modifier (2 point)
2
Part II: Multiple choice: circle the correct answer (1.5 point each)
Part III: Find the error(s) and correct it if there is any in following program (3 points)
3
1. What is the output of this program (3 points)
class Vehicle {
static String Model= "BMW";
static double Price= 250000.0;
Vehicle () {}
public static String tostring() {
return ( "Model =" + Model + "Price " + Price ); }
}
//=====================================
class Car extends Vehicle {
static String Manufacturer= "Toyota";
Car() {}
public static String tostring(){
System.out.println(y);
array[4] = 20;
y = 42 / x;
System.out.println(array[4]);
}
catch (ArithmeticException e) {
System.out.println("Divide by 0" ); }
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(" Array index out of bound ");}
finally {
System.out.println(" the program finished!");}
}
}
student Full Name, Dorm No and school Tostring which returns full
information of a student
Student President Full Name, Dorm No and salary getpayment which returns salary of
the student president
1. Given the above information, by applying the concept of inheritance, write the full java program for
each class. )(5 points)
Hint:
o Identify the super and sub class
o Use constructor to initialize the instance variables
4
o Create a test class called TestStudent
o Create one object for each of the above class within the TestStudent class
o Display the salary of each object using the getpayment() method of each classes)…
5
2. Given an interface
interface circle {
final double pi= 3.142;
double computArea();
}
Create a class cylinder to implement an interface circle. The area of a cylinder is the product of Pi ,
radius square, and height of the cylinder.(3 points)
6
3. Create a class called Book with Title and Price as instance variables, and a method called
SaveToTextFile. Within the body of this method, write all the necessary line of instructions so as to
accept four books information from the keyboard and store them into the text file (c:\Books.txt).
(5points)
7
4. Write a class called Invoice with unit price and total quantity as instance variable and a method
called totalPay .The code within this method must accept the value for unit price and total quantity
variable from the keyboard and return the quotient (division) total quantity over unit price variables.
In addition to this, Within this method include all the possible exceptions handle issues (like input
mismatch, negative value for price and quantity… ) (5points) (hint define your exceptions to handle
negative price )