You are on page 1of 6

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 COMP1307

Date and Time Wednesday 9th Dec 2009 (2 hours)

BAHRAIN 15:00 BOTSWANA 15:00


GREECE 15:00 HONG KONG 18:30
KENYA 16:00 LONDON 13:00
MALAYSIA 18:30 MALTA 14:00
MALAWI 14:00 MAURITIUS 18:00
MYANMAR 15:30 RWANDA 14:00
SAUDI ARABIA 16:00 SINGAPORE 17:30
SRI LANKA 18:30 SOUTH AFRICA 15:00
SYRIA 14:00 TANZANIA 16:00
TRINIDAD 09:30 UAE 17:00
ZAMBIA 15:00 BANGLADESH 18:30
VIETNAM 17: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 ELECTRONIC DEVICES ARE NOT PERMITTED


FINAL

SECTION A – COMPULSORY

1.
a) A programmer has written the following Java class to represent a person:

class Person {
private String name;
private int age;

public Person(String name, int age) {


setName(name);
setAge(age);
}

// get methods
public String getName() {
return name;
}
public int getAge() {
return age;
}

// set methods
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
}

This class is fine as far as it goes, but it fails to satisfy the design rules for
Java Canonical Form.

(i) Give FIVE design rules that should be applied for the above class to
be in canonical form

[6 marks]

(ii) Add the necessary code to the above class to satisfy THREE of these
rules

[9 marks]

b) Give SIX aspects that you would expect to see include a full definition of a design
pattern. Explain briefly why it is.
[9 marks]

QUESTION 1 IS CONTINUED ON PAGE 3

Object Oriented Software Development


COMP1307
Page 2 of 6
FINAL

QUESTION 1 CONTINUED FROM PAGE 2

c) As a senior software consultant, you are required to give a seminar on one of the
following design patterns to junior colleagues: Factory or Adapter. In particular
you should indicate the classification (according to the Gang of Four classification
scheme) of the design pattern, describe the problem it tries to solve and the
solution, and discuss possible tradeoffs.

[10 marks]

d) Why do we design software into tiers? Explain your answer using the
Data Access Object design pattern as an example.
[6 marks]

Object Oriented Software Development


COMP1307
Page 3 of 6
FINAL

SECTION B – Answer any TWO questions.

2. a) Critically compare and contrast frameworks with design patterns.

[10 marks]

b) You are given the code for the Student and TestStudent classes:

01 public class Student {


02 public Student(String n) {
03 name = n;
04 grade = 0;
05 }
06
07 public String toString()
08 {
09 return "[name=" + name + ", grade=" + grade + "]";
10 }
11
12 public void setGrade(float s)
13 {
14 grade = s;
15 }
16 private String name;
17 private float grade;
18 }

01 import java.util.*;
02
03 public class TestStudent
04 {
05 public static void main(String[] args)
06 {
07 Map student = new HashMap();
08 student.put("5464", new Student("Angela"));
09 student.put("2546", new Student("Harry"));
10 student.put("7935", new Student("Gary"));
11 student.put("5527", new Student("Frances"));
12 System.out.println(student);
13 student.remove("2546");
14 student.put("5527", new Student("Frances"));
15 System.out.println((Student)student.get("7935"));

16 Set entries = student.entrySet();


17 Iterator iter = entries.iterator();
18 while (iter.hasNext())
19 {
20 Map.Entry entry = (Map.Entry)iter.next();
21 String key = (String) entry.getKey();
22 Student value = (Student) entry.getValue();
23 System.out.println("key=" + key + ", value=" + value);
24 }
25 }
26 }

The code executes correctly when run. Explain in detail what you would expect to
happen when the code is run.
[14 marks]
QUESTION 2 IS CONTINUED ON PAGE 5

Object Oriented Software Development


COMP1307
Page 4 of 6
FINAL

QUESTION 2 CONTINUED FROM PAGE 4

c) Describe the characteristics of the TreeMap concrete collection class, and


describe what difference it would make if HashMap is replaced with
TreeMap in the TestStudent code in b).

[6 marks]

Object Oriented Software Development


COMP1307
Page 5 of 6
FINAL

3.
(a) Discuss the “Producer-Consumer” problem and explain how it may be
solved. There is no need to write any code.
[15 marks]

(b) Give an account of run-time exception handling in Java. Include a


discussion of the distinction between errors and exceptions and give an
example of a typical run-time error. Also, explain why and how you might
want to create your own exception class(es).

Illustrate your answer with short segments of Java code.


[15 marks]

4.
(a) Servlets and Java Server Pages (JSPs) are related technologies for adding
(Java) server-side functionality to a Web site. Programmers often get
confused between the two, especially when they are told that a JSP is
transformed into an equivalent servlet the first time it is used. Compare and
contrast these two technologies, stressing the relative advantages and
disadvantages of each.

[15 marks]

(b) (i) What do you understand by unit testing? In the context of unit testing,
what do you understand by the terms test harness and test stub.

[6 marks]

(ii) Give a brief account of the unit testing framework JUnit.

[9 marks]

Object Oriented Software Development


COMP1307
Page 6 of 6

You might also like