Académique Documents
Professionnel Documents
Culture Documents
Level Three
BAHRAIN – 15:00
GREECE – 15:00
HONG KONG – 18:30
LONDON – 13:00
MALTA – 15:00
MALAYSIA – 18:30
SINGAPORE – 18:30
SYRIA – 14:00
TRINIDAD – 09:30
ZAMBIA – 15:00
1. (a) Study the code below. Explain whether you think the Accounts class
meets the canonical form of classes. If not, re-write the code and
include any missing code in your answer. You do not need to write the
details of code for any new methods, just state the method signature to
explain what the code would be required to do (state the return type,
input parameters etc).
(b) You have been asked to explain to a group of junior colleagues good
guidelines for the design of classes (excluding the canonical form).
Write a brief explanation of these guidelines and explain why they are
considered to be good practice.
[5 marks]
________________________________________________________
Course Title: Object-Oriented Software Development
COMP 1307
Page 2 of 8
APPROVED
import java.io.*;
class DataLog
implements Serializable
{
int value = 0;
DataLog() { }
void setValue(int x)
{
value = x;
}
int getValue()
{
return value;
}
}
Question 2 continued:
(b) Explain what happens when the Test class is loaded, and predict the
exact output. You do NOT have to explain every single line of the code
in detail.
[10 marks]
(c) There are two examples of the use of the Decorator design pattern in
the code. Identify where in the program this pattern is used.
[2 marks]
(d) For the Decorator design pattern, explain its intent (what it is meant to
do) and its applicability (where it is used).
[5 marks]
________________________________________________________
Course Title: Object-Oriented Software Development
COMP 1307
Page 4 of 8
APPROVED
Describe for such application frameworks the main characteristics and design
requirements.
[9 marks]
(c) The design of the Java GUI components hierarchy illustrates a commonly-
used design pattern. Name this pattern and explain its intent and applicability.
[5 marks]
(d) Briefly discuss the role of layout managers in Java GUI systems.
[5 marks]
[16 marks]
________________________________________________________
Course Title: Object-Oriented Software Development
COMP 1307
Page 5 of 8
APPROVED
5. (a) Study the code below. It comprises two classes, Count and Wotsit.
import java.util.*;
import java.io.*;
class Count
{
public String word;
public int i;
try
{
BufferedReader instream = new BufferedReader(new
FileReader("jackjill.dat"));
while ((line = instream.readLine()) != null)
{
StringTokenizer st = newStringTokenizer(line, delim);
while (st.hasMoreTokens())
{
word = st.nextToken().toLowerCase();
count = (Count)words.get(word);
if (count == null)
{
words.put(word, new Count(word, 1));
}
else
{
count.i++;
}
}
}
}
Question 5 is continued on the next page
________________________________________________________
Course Title: Object-Oriented Software Development
COMP 1307
Page 6 of 8
APPROVED
Question 5 continued
catch (Exception e)
{
}
while (iter.hasNext())
{
Map.Entry entry = (Map.Entry)iter.next();
word = (String)entry.getKey();
count = (Count)entry.getValue();
System.out.println(word + "\t" + count.i);
}
}
}
(b) Explain what happens when the Wotsit class is loaded, and predict the
output. You do NOT have to explain every single line of the code in
detail.
[10 marks]
(d) Explain the effect on the output of altering line 20 of the original
program to:
________________________________________________________
Course Title: Object-Oriented Software Development
COMP 1307
Page 7 of 8
APPROVED
(d) Explain the lifecycle of a thread and how thread priorities are
implemented by the Java virtual machine.
[12 marks]
________________________________________________________
Course Title: Object-Oriented Software Development
COMP 1307
Page 8 of 8