You are on page 1of 8

APPROVED

EXAMINATION PAPER: ACADEMIC SESSION 2006/2007

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 Friday 25th May 2007 3 hours

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

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

Course Title: Object-Oriented Software Development


COMP 1307
APPROVED

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).

class Account implements java.lang.Cloneable {


int accountNumber;
public Account(int num) {
accountNumber = num;
}
public void setAccountNumber(int num) {
accountNumber = num;
}
public Account clone() {
return this;
}
public int getAccountNumber() {
return accountNumber;
}
}

public class ManageAccounts {


public static void main(String[] args) {
Account a1 = new Account(0),
a2 = new Account(0);
a1.setAccountNumber(12345);
a2 = a1.clone();
System.out.println(a1.getAccountNumber());
System.out.println(a2.getAccountNumber());
}
}
[15 marks]

(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]

(c) Large scale systems development can potentially result in hundreds or


thousands of source files. Explain how packages provide the
programmer with a way to manage and organise files. Your answer
should also include an explanation of what access classes within a
package have to each other’s data and methods.
[5 marks]

________________________________________________________
Course Title: Object-Oriented Software Development
COMP 1307
Page 2 of 8
APPROVED

2. (a) Study the code below.

import java.io.*;

class DataLog
implements Serializable
{
int value = 0;

DataLog() { }

void setValue(int x)
{
value = x;
}

int getValue()
{
return value;
}
}

public class Test


{
public static void main(String [] args)
{
try
{
DataLog w, r;
w = new DataLog();
r = new DataLog();
FileOutputStream outp = new FileOutputStream("tempFile");
ObjectOutputStream outpObject = new
ObjectOutputStream(outp);
w.setValue(12);
outpObject.writeObject(w);
outpObject.close();
System.out.println("Value 1:" +r.getValue());
FileInputStream inp = new FileInputStream("tempFile");
ObjectInputStream inpObject = new ObjectInputStream(inp);
r = (DataLog)inpObject.readObject();
System.out.println("Value 2: " + r.getValue());
inpObject.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}

Question 2 continues on the following page


________________________________________________________
Course Title: Object-Oriented Software Development
COMP 1307
Page 3 of 8
APPROVED

Question 2 continued:

Explain what the term “implements Serializable” in the signature of the


Datalog class means.
[4 marks]

(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]

(e) As part of a system which implements an on-line chess-playing


program, it is required that the state of a player’s chess board be sent as
an object to a central games server. Suggest how this state data might
be represented in an object.
[4 marks]

________________________________________________________
Course Title: Object-Oriented Software Development
COMP 1307
Page 4 of 8
APPROVED

3. (a) An application framework has been defined as a set of co-operating classes


that represent re-usable designs of software systems in a particular
application domain. You will have looked at the Java Collections framework,
the Java graphical user interfaces framework and the Java input/output
framework.

Describe for such application frameworks the main characteristics and design
requirements.
[9 marks]

(b) Explain the difference between an application framework and a design


pattern.
[6 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]

4. (a) You are currently employed as a consultant to a large supermarket has


a chain of stores across the country. They are developing an e-
commerce website so that they can sell their good over the internet.
They expect a high volume of sales and you have been called in to
advise on the system architecture. The purpose of this morning’s
meeting is to discuss which JDBC driver to use to link to their Oracle
database. Prepare a critical evaluation of the different types of JDBC
driver and make notes on the driver you would recommend and why.

[16 marks]

(b) Compare the lifecycle of applets and servlets.


[9 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;

public Count(String ww, int ii)


{
word = ww;
i = ii;
}
}

public class Wotsit


{
public static void main(String [] args)
{
Map words = new HashMap(); // Line 20!
String delim = " \t\n.,:;?!-/()\"\'";
String line, word;
Count count;

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)
{
}

Set set = words.entrySet();


Iterator iter = set.iterator();

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);
}
}
}

The program is to be used in conjunction with this text file (jackjill.dat)


which contains the following:

Jack fell down


And broke his crown
And Jill came tumbling after.

First, explain what happens when when an object of type Count is


instantiated.
[3 marks]

(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]

(c) Suppose the Collection classes (including Hashtable and Vector)


were not available, and the only datastructure available is the array.
Without writing any code, explain how you could write a program
that would do the same job as Wotsit.
[8 marks]

(d) Explain the effect on the output of altering line 20 of the original
program to:

TreeMap words = new HashMap();


[4 marks]

________________________________________________________
Course Title: Object-Oriented Software Development
COMP 1307
Page 7 of 8
APPROVED

6. (a) Explain why contracts of methods are considered good software


design. Your answer should include an example. Clearly state the
issues that can arise if contracts are not used.
[13 marks]

(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

You might also like