Sunteți pe pagina 1din 10

APPROVED

EXAMINATION PAPER: ACADEMIC SESSION 2005/2006

Campus Maritime Greenwich

School Computing and Mathematical Sciences

Department Computer Science

Level Three

TITLE OF PAPER Object Oriented Software Development

COURSE CODE COMP1307

Date and Time Wednesday 31st May 2006 – 3HRs


London 13.30 Hong Kong 18.00
Trinidad 09.30 Malta 15.00
Malaysia 18.00 Bahrain 15.00
UAE 16.00 Singapore 18.00
Zambia 14.30 Greece 15.00

Answer any FOUR of the following SIX questions.


Each question is worth 25 marks.
If you answer more than four questions, marks will ONLY be awarded for your
FOUR best answers.
CALCULATORS AND ELECTRONIC DEVICES ARE NOT PERMITTED

_________________________________________________________________
Object Oriented Software Development
COMP1307
APPROVED

1. (a) You have been asked to give a seminar to a local small software
development company on why contracts of methods are considered
good software design. You will need to discuss the reasons for using
contracts of methods and should provide an example of a contract
with an explanation of it. Prepare key notes for your talk.

[12 marks]

(b) Clearly state which of the methods in the class below are required to
meet the canonical form of classes and why? Are there any methods
missing, if so clearly state which methods and why they are needed?

[13 marks]

public class A_Class extends Object implements Cloneable,


java.io.Serializable {

public A_Class() {// body of method here


}

public boolean equals(Object o) { // body of method here


}

public makeCopy() { // body of method here


}

public int hashCode() { // body of method here


}

private void readObject(java.io.ObjectInputStream in)


{ // body of method here
}

private void saveObject(java.io.ObjectOutputStream out)


{ // body of method here
}
}

__________________________________________________________________ 2
Object Oriented Software Development
COMP1307
APPROVED

2. (a) Java provides two mechanisms for writing threads. State these
mechanisms and compare their use.

[5 marks]

(b) Discuss the “bounded queue” problem and briefly describe a solution
to it outlining the complexities of solving this problem.

[12 marks]

(c) Java exceptions can be divided into three main categories, what are
these categories? Explain the advantages of the exception handling
mechanism in Java and give an example of how exceptions may be
handled.
[8 marks]

__________________________________________________________________ 3
Object Oriented Software Development
COMP1307
APPROVED

3. You have been called to a small local company as an advisor to their small
IT team (3 people) who have developed an in-house stock control system
using mainly JSPs and servlets. They are finding it increasingly harder to
maintain over time as the business logic is all muddled up with presentation
code etc. They are seeking your advice about how to write more
maintainable code.

(a) Explain the basics of how tag libraries work and the benefits that
they might obtain as a result of using them.

[10 marks]

(b) Write a brief report for the company outlining the advantage of the
Struts framework and explain why this structure might help them
produce more maintainable code in future.

[15 marks]

__________________________________________________________________ 4
Object Oriented Software Development
COMP1307
APPROVED

4. 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.
[4 marks]

Question 4 continues on the following page

__________________________________________________________________ 5
Object Oriented Software Development
COMP1307
APPROVED

Question 4 continued:

(b) Predict what the program above does when loaded, and what is the
output. 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]

(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 the class called Counter) with an instance variable
storing the number. The Singleton design pattern could be used in
such a case.

Explain the purpose of the Singleton pattern and say why it would
be appropriate to use it in the example given.

[5 marks]

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


behavioural types. Explain the characteristics of these three types.

[6 marks]

__________________________________________________________________ 6
Object Oriented Software Development
COMP1307
APPROVED

5. (a) The Java Collections Framework contains the


following:

• Interfaces
• Implementations
• Algorithms

Explain these three terms.


[6 marks]

(b) What are the benefits of the Java Collections Framework?

[6 marks]

(c) Consider the code listed below:

1. import java.util.*;
2. import java.io.*;

3. public class Test {


4. static public void main(String[] args) {
5. HashSet x = new HashSet();
6. BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
7. String delim = " \t\n.,:;?!-/()[]\"\'";
8. String line;
9. int y = 0;
10. try {
11. while ((line = in.readLine()).length() != 0) {
12. StringTokenizer st = new StringTokenizer(line, delim);
13. while (st.hasMoreTokens()) {
14. y++;
15. x.add(st.nextToken().toLowerCase());
16. }
17. }
18. } catch (IOException e) {}

19. System.out.println(y);
20. System.out.println(x.size());
21. }
22. }

Question 5 continues on the following page

__________________________________________________________________ 7
Object Oriented Software Development
COMP1307
APPROVED

Question 5 continued:

Explain in detail what this program does when loaded, how it is


used and what sort of output is obtained. You may use the line
numbers in your explanation. Indicate any design patterns used.

[10 marks]

(d) The program in (c) uses a HashSet object. What differences would
be noticed if a TreeSet object were used instead?

[3 marks]

__________________________________________________________________ 8
Object Oriented Software Development
COMP1307
APPROVED

6. (a) You are involved with the implementation of a simple graphics


system.This is the specification:

The system enables the user to select a shape (for example a square
or a circle) from a menu. The shape is then drawn on the “drawing
screen”, and the user can then, by selecting from menus, change the
position, size and colour of the drawn shape. A drawn shape can
also be deleted. The screen can display many shapes at once, and
store the whole screen to a file, so that later the screen can be
reloaded.

As a start, an abstract base class with one abstract method is


implemented.

1. public abstract class Shape {

2. double x_position, y_position, width, height;

3. public abstract double area ();

4. }

Explain the terms abstract and base class as used here.


[4 marks]

(b) x_position is to store the x position of the upper left-hand corner of


the shape to be drawn (or the upper-left-hand corner of the
“bounding box” for shapes like circles).

y-position is to store the y position of the shape.

width is to store the width of the shape (or the upper-left-hand


corner of the “bounding box” for shapes like circles).

height is to store the height of the shape.

State the code for a concrete class called Square, a subclass of


Shape, with a “no-args” (no arguments) constructor setting

Question 6 continues on the following page


__________________________________________________________________ 9
Object Oriented Software Development
COMP1307
APPROVED

Question 6 continued:

x_position as 50, y_position as 50, width as 20 and height as 20.

[4 marks]

(c) State the code for a class called TestShape with a main() method
creates an instance of Square and prints (to the standard output) its
area.
[3 marks]

(d) Draw a UML diagram with the classes Shape, Square and TestShape
included.
[4 marks]

(e) As objects are created and deleted , it is required to create a “list” of


them using some suitable datastructure. Suggest a suitable
datastructure and state a fragment of code showing how two objects
could be created, added to the list and deleted from the list.

[6 marks]

(f) Storing the drawing screen could be done by writing data from the
object list to a file. Explain how this can be done.

[4 marks]

__________________________________________________________________ 10
Object Oriented Software Development
COMP1307

S-ar putea să vă placă și