You are on page 1of 4

FINAL

EXAMINATION PAPER: ACADEMIC SESSION 2009/2010

Campus Maritime Greenwich

School Computing and Mathematical Sciences

Department Computer Science

Level Three

TITLE OF PAPER Object Oriented Software Development

COURSE CODE COMP 1307

Date and Time Wednesday 2nd June 2010

Duration 2 hours

BAHRAIN 15:00 BOTSWANA 14:00


GREECE 15:00 HONG KONG 18:30
KENYA 15:00 LONDON 13:00
MALAYSIA 18:30 MALTA 14:00
MALAWI 14:00 MAURITIUS 16:00
MYANMAR 16:30 RWANDA 14:00
SAUDI ARABIA 15:00 SINGAPORE 17:30
SRI LANKA 17:30 SOUTH AFRICA 14:00
SYRIA 15:00 TANZANIA 15:00
TRINIDAD 09:30 VIETNAM 18:30
ZAMBIA 14:00 BANGLADESH 18:30

You MUST answer question 1 which is worth 40 marks.

Answer TWO questions from the remaining THREE questions, questions 2 to 4 which are worth 30
marks each. If you answer all THREE questions from questions 2 to 4, marks will ONLY be awarded
for your TWO best answers.

CALCULATORS AND OTHER ELECTRONIC DEVICES ARE NOT PERMITTED


FINAL

Section A (Compulsory)

1.
(a) Explain how assertions may be used to support contracts in Java. Your answer
should outline the advantages and disadvantages of using them and include an
example of an assertion.
[9 marks]

(b)
i) What are the advantages of substitutability of subtypes? Your answer
should explain the principle of substitutability of subtypes and include an
example (in English, not Java code).
[5 marks]

(ii) Study the code below. Will it compile? Explain your answer in detail. If
you don’t think the code will compile, identify any changes you could
make so that it will compile. Line numbers are included to assist you with
referring to specific code in your explanation.
[6 marks]

(iii)
1. class BIGCAT {}
2. class BIGBIRD {}
3. class TIGER extends BIGCAT {}
4. class EAGLE extends BIGBIRD {}
5. public class Substitute {
6. public static void main(String[] args) {
7. BIGCAT w;
8. BIGBIRD y;
9. TIGER x;
10. EAGLE z;
11. x = new TIGER();
12. z = new EAGLE();
13. z = y;
14. w = x;
15. }
16. }

(c)
(i) Explain why design patterns are used in the software development process
and highlight the benefits that can be achieved.
[10 marks]

(ii) The presentation tier of a large application has to handle many user
requests and ensure they are all processed. A typical solution to managing
the requests is to use the Front Controller Pattern. Give an outline of how
this patterns works and the problem is it trying to solve.
[10 marks]

___________________________________________________________________
COMP1307 Object Oriented Software Development
Page 2 of 4
FINAL

Section B (answer any TWO questions)

2. You have been asked to design a website for an on-line Chinese take-away
restaurant. Instead of forming a queue at the counter to order your food and
waiting for your order, the new website will allow customers to order and pay
directly from their smart phones (3G or wi-fi capable). The screen will allow
customers to choose food and drink, and then place an order and pay on-line with
a credit card. An order number will be issued to the customer for each order as
well as an approximate time for collection. The food will then be delivered to the
counter for pick up when they are ready.

(a) The system you have been asked to design is required to use a combination of
JSP and Servlet technologies as appropriate. Write a brief report stating why
you would choose to use each of these technologies and give examples related
to the above scenario explaining for what parts of the system you would
choose to use JSPs and for what parts you would choose to use Servlets. (You
are not required to write any Java code).
[16 marks]

(b) Outline the Struts framework and discuss whether you would choose to use it
in the Chinese take-away restaurant scenario given above.
[14 marks]

3.
(a) What is an exception? Explain why Java provides a mechanism for handling
exceptions and give an example of how this mechanism works.
[10 marks]

(b) Explain why the following code will throw an exception.

int a[]={15, 2, 5, 9, 81, 32, 540, 67};

try {
for ( int i=0; i<9; i++ ) {
System.out.println(a[i]);
}
}
catch (Exception e) { }
[4 marks]

(c) The code given below shows one way of declaring and starting a new thread.

public class MyThread extends Thread {

public void run()


{
// thread body
}
}

___________________________________________________________________
COMP1307 Object Oriented Software Development
Page 3 of 4
FINAL

To start the thread you could call:

(new MyThread()).start();

Defining threads by directly extending the Thread class is one option provided
by Java. Explain why it may not always be possible to use this option, and re-
write the code for the above class showing an alternative means of defining a
thread. You answer should include the code defined above which calls the
start method, with a brief explanation of how it works.
[6 marks]

(d) Describe the lifecycle of a thread and how the Java virtual machine
implements thread priorities.
[10 marks]

4.
(a) Give the properties of an abstract class and explain why a software engineer
might choose to abstract classes in software design.
[6 marks]

(b) In the context of the code shown below, explain the meaning and effect of the
key words “static”, “final” and “protected”. You will notice that neither class
has a modifier, e.g. “public” in the class declaration. What does this mean in
terms of how accessible these classes are by others?

1. abstract class Shape {


2. public abstract double area();
3. public abstract double perimeter();
4. }

5. class Circle extends Shape {


6. public static final double PI = 3.141592;
7. protected double r;
8. public Circle(double r) { this.r = r; }
9. public double getRadius() { return r; }
10. public double area() { return PI*r*r; }
11. public double perimeter() {return 2*PI*r;}
12. }
[8 marks]

(c) You are currently a consultant to a small company which wants you to set up a
database to manage their staff timesheets. Some staff work from home and
they would like the system to be available over the internet. Speed is not a
priority as there are only a few staff. They expect to use an Access database
which they all have readily available on their home machines. As a first step
you have been asked to write a critical review comparing and contrasting the
four types of JDBC driver and to clearly state which one you would
recommend they use and why.
[16 marks]

___________________________________________________________________
COMP1307 Object Oriented Software Development
Page 4 of 4

You might also like