Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

THE OPEN UNIVERSITY OF SRI LANKA

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING


BACHELOR OF SOFTWARE ENGINEERING/BACHELOR OF TECHNOLOGY

EEI4362_EEX4362 Object Oriented Design

Answers to this assignment should be sent by registered post to the following address or should be
placed in the assignment box placed in the Department at Colombo Regional Centre.

The Course Co-ordinator – EEI4362_EEX4362


Faculty of Engineering Technology
The Open University of Sri Lanka
Nawala, Nugegoda.

(Answers should be clear, and readable. Use A4 paper. Unclear, unreadable, copied and direct
reproduction from the textbook will not gain any points for the answers. Delayed submissions will count
minus marks.)

Assignment 1 Submit on or before 05-04-2021

Answer all Questions.


(This assignment will be assessed by viva voce. You should be able to demonstrate the
implementation questions and explain)

Q1.

a. Briefly explain the difference between interface and abstract class.

b. What is wrong with the following interface? Correct it.

public interface Figures{

public void printMessage (String s){


System.out.println ("This figure is " + s ); }
public double area ( ) ; // to calculate the area of the figure
}
c. Design a class Rectangle that implements the corrected interface of section (b).

d. 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 field of type ArrayList that stores objects of type Car.
i. Class Car is an abstract class. Explain the role of an abstract class.
ii. 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.
iii. Write a Java version of class ClassicCar assuming it has this constructor:
public ClassicCar (double price, int year)
and that the method calculateSalePrice ( ) returns 10,000 as the sale price of the car.
iv. Write a Java version of class SportCar assuming it has this constructor:
public SportCar(double price, int year)

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
v. Write a Java version of class CarExhibition assuming it has this constructor:
public CarExhibition( )
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.
[25 Marks]

Q2.
a. Designing an electronic voting machine is a challenging task. You are asked to implement a
very simplified voting machine class with the following specification. A voting machine has a list of
candidates and the following methods:
a) addCandidate(String name)
/* Add a candidate with the name to the list */
b) castVote(String name)
/* Cast a vote to the candidate with the name */
c) printResults()
/* Print out the number of votes each candidate has received. The order does not matter */

Assume that only two attributes of a candidate, namely, the name and number of votes, are of interest
here, and the size of the candidate list is unknown in advance.
b.

i. Write the java code segments to do the followings


1. Calculate the factorial of an integer (factorial =n*(n-1)*(n-2)*(n-3)*…*1.
2. Calculate the average of numbers in an array.

ii. Explain the importance of thread safety in concurrent programming.

iii. Explain how you would debug a program written in java with examples.

iv. What are the different types of parameter passing? State the advantages of each.

c.

i. Explain the refactoring techniques with your own words.

ii. Consider the following code snippet,

area1=2*22/7*20;
area2=2*22/7*10;
area3=2*22/7*25;
area4=2*22/7*60;

Explain how you would re-factor the above code to improve reusability and
maintenance.
[25 Marks]

Q3.
a. What is meant by polymorphism? Why do Java languages which support inheritance also
support polymorphism?

b. Assume we have three classes: Person, Teacher, and Student. Teacher and Student are both
subclasses of Person.
Which of the following assignments are legal, and why?
Person p;
Teacher t;
Student s;
t = new Teacher ( );
p = t;
s = (Student) t;
s = (Student) p;
p = new Student ( );
t = new Person ( );
t = p;

c. Write the definition and implementation of the class Robot that has one field called position of
type class Point and three methods. The methods are:

- moveLeft that moves the robot from the current position to the left for d distance.
- moveRight that moves the robot from the current position to the right for d distance.
- moveForward that moves the robot forward for d distance.
Class Point has two fields: x and y of type int, which represent the coordinates of a point in x-y
plane and two accessor methods to get the values of x and y.
[25 Marks]

Q4.
a. Microsoft pattern and practices enterprise library is a collection of reusable software
frameworks. List three software components that are coming under this.
b. Take a one framework you listed in (a) and elaborate the usage of it with pros and
cons.
c. Java struts is a popular among java developer. Identify the major components in the
framework. How you would use this framework in your project.
d. Service locator is a J2EE design pattern. As you understand draw the UML diagram
to explain this pattern.
e. You have been asked to use an industry framework to map your objects into relation
database tables. What is the framework that you would recommend for your developer
team?
f. Consider the following scenario

e is a spread object which contain the table of data and there are three objects namely
linegraph, pieChart and histogram which use the spread sheet object to draw itself with
data. When the spread sheet object is changed you need to redraw all the graph objects.
Give a solution using an appropriate design pattern. Solution should include a UML
design and a skeleton implementation using java.
[25 Marks]

You might also like