Professional Documents
Culture Documents
Level Three
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.
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;
// 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]
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]
[10 marks]
b) You are given the code for the Student and TestStudent classes:
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"));
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
[6 marks]
3.
(a) Discuss the “Producer-Consumer” problem and explain how it may be
solved. There is no need to write any 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]
[9 marks]