You are on page 1of 6

APPROVED

EXAMINATION PAPER: ACADEMIC SESSION 2010/2011

Campus Maritime Greenwich

School Computing and Mathematical Sciences

Department Computer Science

Level Three

TITLE OF PAPER Object Orientated Software Development

COURSE CODE COMP1307

Date and Time Wednesday 1st December 2010 (2 hours)

BAHRAIN 15:00 BOTSWANA 14:00


GREECE 15:00 GHANA 13.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


APPROVED

Section A – (Compulsory)

1. (a)
(i) Explain how packages provide programmers with a way to manage
and organise class files within a large scale system. Your answer should
include an explanation of what access classes within a package have to each
other’s data and methods.
[8 marks]

(ii) The Accounts class given below meets two of the requirements for
the canonical form of classes – it implements the Cloneable and Serializable
interfaces. Describe the remaining requirements for canonical form and
implement them. You do not need to write the details of code for any new
methods, just write the method signatures and explain what code would be
required.

class Account implements java.lang.Cloneable, java.io.Serializable {


int accountNumber;
public Account(int num) {
accountNumber = num;
}
public void setAccountNumber(int num) {
accountNumber = num;
}
public int getAccountNumber() {
return accountNumber;
}
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
[12 marks]

Question 1 continues on the next page

COMP1307 – Object Orientated Software Development


Page 2 of 6
APPROVED

Question 1 continued from the previous page

(b) You are introducing good practice for object-oriented system development
to a company which has no previous experience of design patterns. As a
senior software consultant, you gave a seminar on design patterns. The
following questions were asked by the audience at the end.

(i) Design patterns can be organised into creational, structural and


behavioural types. Explain the characteristics of these three
categories of design patterns.
[6 marks]

(ii) Why should software developers use design patterns?

[6 marks]

(iii) What is an anti-pattern? How does an anti-pattern differ from a


pattern?
[8 marks]

COMP1307 – Object Orientated Software Development


Page 3 of 6
APPROVED

Section B – (Answer any TWO questions)

2. The code below is part of a system which simulates robots. Robot objects can be
created and information about method calls (for example the number of times the
move() method is called) is computed.

1. public class Robot {

2. public int x, y;
3. private int instanceMoveCount;
4. static private int classMoveCount;

5. public Robot(int x, int y) {


6. this.x = x;
7. this.y = y; }

8. public void move(int dx, int dy) {


9. x += dx; y += dy;
10. instanceMoveCount++;
11. classMoveCount++;}

12. public int getInstanceMoveCount() {


13. return instanceMoveCount;}

14. public static int getClassMoveCount() {


15. return classMoveCount;}

16. public static void main(String[] args) {


17. Robot r1 = new Robot(0, 0);
18. Robot r2 = new Robot(0, 0);
19. r1.move(20, 10);
20. r1.move(10, 20);
21. r2.move(10, 10);
22. System.out.println(r1.getInstanceMoveCount());
23. System.out.println(r2.getInstanceMoveCount());
24. System.out.println(Robot.getClassMoveCount());
25. }
}

(a) Explain the differences between class (static) methods and instance
methods.
[6 marks]

(b) Predict what the program above does when loaded, and what the output will
be. You may use the line numbers in your explanation, but you do NOT
have to explain every line – just explain the main functionality.
[10 marks]

Question 2 continues on the next page

COMP1307 – Object Orientated Software Development


Page 4 of 6
APPROVED

Question 2 continued from the previous page

(c) Another way of keeping track of the total number of times the move()
method is executed would be to use some object (say an instance of a class
called Counter) with an instance variable storing the number. The Singleton
design pattern could be used in such a case.

(i) Describe the structure of the Singleton design pattern.

[6 marks]

(ii) Explain the purpose of the Singleton pattern and say if it would be
appropriate to use it in the given code example and explain why.

[8 marks]

3. (a) Discuss the DAO pattern and explain its use of the Transfer Object Pattern in
JEE applications.
[15 marks]

(b) Compare and contrast the use of servlets and java server pages for building
dynamic Web applications. In your answer, stress the relative advantages
and disadvantages of these two technologies.
[15 marks]

4. (a) Give an account of Exception Handling in Java. Illustrate your answer by


considering the following program, which may give rise to three different
types of exception:

An ArrayIndexOutOfBoundsException which happens if there are less than


two command line arguments.
A NumberFormatException which happens if one or both of the arguments
are not whole numbers.
An ArithmeticException which happens if the first argument is a whole
number and the second argument is 0.

Describe how you would rewrite this program in such a way that each of
these exceptions could be handled.

class Exceptions {
public static void main(String[] args) {
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
int c = a / b;
System.out.println("The answer is " + c);
}
}
[9 marks]

Question 4 continues on the next page


COMP1307 – Object Orientated Software Development
Page 5 of 6
APPROVED

Question 4 continued from the previous page

(b) The Java API classes contain the following hierarchy:

The exception classes mentioned in part (a) are all subclasses of


RuntimeException.

Give an example of a subclass of Error and a subclass of Exception


which is not a subclass of Runtime Exception and explain carefully
the distinction between Errors, Exceptions and RuntimeExceptions.

[9 marks]

(c) (i) Give an account of the different testing phases that are commonly
used in the development of software systems.

[6 marks]

(ii) Identify the testing phases of a Java software system where the
framework JUnit may be used, and describe briefly the way this
framework operates.
[6 marks]

COMP1307 – Object Orientated Software Development


Page 6 of 6

You might also like