Sei sulla pagina 1di 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 Thursday 7th December 2006 3 hours

LONDON – 13.30 BAHRAIN – 15.00

HONG KONG – 18.00 UAE – 16.00

TRINIDAD – 09.30 SINGAPORE – 18.00

MALTA – 15.00 ZAMBIA – 14.30

MALAYSIA – 18.00 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
Page 1 of 10
APPROVED

1. a. The state of an object can be referred to as “transient” or “stable”.


Explain what these two concepts mean.
[4 marks]

b. Explain what an “invariant” of a class is and why we might wish to


establish this. As a developer implementing a class, suppose you have
been given the class details and its invariants, clearly state what you
need to establish in order to preserve the invariants in your
implementation.
[6 marks]

c. Discuss what the key elements of a class that follows the canonical
form should look like and provide outline code for each requirement.
Outline code should include method names etc. but not method
content.
[15 marks]

2. You have been asked to design a website for a new style of on-line coffee
shop. Instead of forming a queue at the counter to order your coffee, waiting
for your order and then sitting down at a table, the new website will allow
customers to order and pay directly from their table. The screen (provided at
each table) will allow customers to choose the type of coffee they want, cakes
etc. and then place an order and pay on-line with a card. The coffee and cakes
will then be delivered to the table when they are ready.

a. The system you have been asked to design is for a small coffee shop
using a combination of JSP and servlet technologies as appropriate.
You have been asked to write a brief report stating why you would
choose to use each and give examples related to the above scenario of
what parts of the system you would choose to use JSPs for and what
parts you would choose to use servlets for.
[13 marks]

b. Outline the Struts framework and discuss whether you would choose to
use it in the coffee shop scenario given above.
[12 marks]

__________________________________________________________________
Object Oriented Software Development COMP1307
Page 2 of 10
APPROVED

3. You have been called in by a small company who have developed a


system using Java. The system has been working reasonably well (only a
few bugs) however, they now need to make some changes to it and are
seeking your advice. The code you have looked at is “like spaghetti” – it
is un-maintainable, poorly structured and does not adhere to good design
principles.

a. With reference to the above system, you have been summoned to


make a presentation to the small IT department of the company
to explain why what they need to do to restructure their existing
code. Your notes for the presentation should focus on the use of
packages, pre- and post- conditions, Java assertions to help test
and the documentation of their Java code, the need use interfaces
etc.
[10 marks]

b. On further inspection you realise that their system would run much
faster if they used threads. Extend your notes for the presentation to
include an explanation of the advantage and disadvantages of using
threads.
[6 marks]

c. The company has expressed an interest in implementing threads


however they are unclear about how threads synchronise their work
together as having one thread update a record whilst another is reading
it, could lead to disastrous consequences. Write a report for the
company outlining the basic principles by which threads can manage
their inter-process communication.
[9 marks]

__________________________________________________________________
Object Oriented Software Development COMP1307
Page 3 of 10
APPROVED

4. A Microsoft Access database (Example.mdb) contains a table Table1 with the


numerical field name and the text field seat, and the values shown below:

Consider the code below which a student has written to extract and output data
from the database:

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import sun.jdbc.odbc.*;

public class Example extends Frame


implements WindowListener, ActionListener
{
private TextArea inputTextArea;
private Button executeButton;
private Label myLabel;

public static void main(String[] args)


{
Example demo = new Example();
demo.doIt();
}

public void doIt()


{
setLayout(new FlowLayout());
setSize(400, 400);
executeButton = new Button("Execute");
add(executeButton);
myLabel = new Label
"SQL query on airline seat database");
add(myLabel);
executeButton.addActionListener(this);
inputTextArea = new TextArea("", 10, 50);
add(inputTextArea);
addWindowListener(this);
setVisible(true);
}

public void actionPerformed(ActionEvent evt)


{
if (evt.getSource() == executeButton)
{
try
{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Question 4 continues on the following page

__________________________________________________________________
Object Oriented Software Development COMP1307
Page 4 of 10
APPROVED

Question 4 continued
Connection con = DriverManager.getConnection
("jdbc:odbc:Driver={Microsoft AccessDriver(*.mdb)};DBQ=Example.mdb");

Statement stmt = con.createStatement();


ResultSet rs = stmt.executeQuery(
"SELECT name, seat FROM Table1 ORDER BY name");

while (rs.next())
{
String name = rs.getString("name");
int seat = rs.getInt("seat");
inputTextArea.append(
name + " " + seat + "\n");
}
stmt.close();
con.close();
}
catch (Exception e)
{
System.err.println(e);
System.exit(1);
}
}
}

public void windowClosing(WindowEvent e)


{
System.exit(0);
}

// dummy implmentations of unused Frame methods


public void windowIconified(WindowEvent e) { }
public void windowOpened(WindowEvent e) { }
public void windowClosed(WindowEvent e) { }
public void windowDeiconified(WindowEvent e) { }
public void windowActivated(WindowEvent e) { }
public void windowDeactivated(WindowEvent e) { }
}

a. Explain what this program does when loaded, and sketch a diagram to show
the form of the GUI with the expected output. You do NOT have to explain
every line – just explain the main functionality, including the purpose of the
methods.
[10 marks]

b. A system using many such Frame classes as the one defined above will
contain many code segments with dummy implementations of unused Frame
methods, as in the code above. Explain how these duplicate code segments can
be eliminated by refactoring, with a suitable code example.
[5 marks]

Question 4 continues on the following page

__________________________________________________________________
Object Oriented Software Development COMP1307
Page 5 of 10
APPROVED

Question 4 continued

c. Explain, with an example, how the use of an alternative layout


manager could be used to improve the appearance of the GUI created
by the program in (a).

[5 marks]

d. Another way to improve the appearance of the GUI would be to use


panels. Briefly explain how the use of panels relates to the Composite
structural design pattern.

[5 marks]

_________________________________________________________________
Object Oriented Software Development COMP1307
Page 6 of 10
APPROVED

5. a. “An object-oriented application framework, or framework for short, is


a set of co-operating classes that represent reusable designs. They often
contain abstract classes and interfaces.”

Explain the terms in italics in the above paragraph.


[4 marks]

b. Describe the main characteristics of the Sets, Lists and Maps collection
types.
[6 marks]

c. Consider the code listed below:

import java.util.*;

public class TestSet


{
public static void main(String[] args)
{
Set set = new HashSet();

set.add("a");
set.add("b");
set.add("c");
set.remove("c");
int size = set.size();
System.out.println("size = " + size);
set.add("a");
size = set.size();
System.out.println("size = " + size);
boolean b = set.contains("a");
System.out.println("b = " + b);
b = set.contains("c");
System.out.println("b = " + b);
Iterator it = set.iterator();

while (it.hasNext())
{
Object element = it.next();
System.out.println(element);
}

String[] array = (String[])set.toArray


(new String[set.size()]);

for (int i = 0; i < array.length; i++)


{ System.out.println(array[i]); }

}
}

Question 5 continues on the following page

__________________________________________________________________
Object Oriented Software Development COMP1307
Page 7 of 10
APPROVED

Question 5 continues

i. Explain what this program does when loaded, and sketch a


diagram to show the expected output. You do NOT have to
explain every line – just explain the main functionality.
[10 marks]

ii. In the above program, there are two different examples of


iteration. Identify these by stating the line numbers of the
relative code.
[2 marks]

iii. One of these is an example of polymorphic iteration. Explain


what is meant by this.
[3 marks]

_________________________________________________________________
Object Oriented Software Development COMP1307
Page 8 of 10
APPROVED

6. a. A number of tools are available to help programmers build multiple


file Java systems. A well-known example of such a tool is Ant. Briefly
explain the problems which arise when is a system is made up of many
files and describe the sort of assistance a tool like Ant can provide to
system builders.
[5 marks]

b. A student has produced the following Java class file (TestClasses.java):


abstract class Class1
{
public void firstMethod ()
{
System.out.println("Hello World!");
}

public abstract void secondMethod ();


}

class Class2 extends Class1


{
public void secondMethod ()
{
System.out.println("Hello Moon!");
}
}

class Class3 extends Class1


{
public void firstMethod ()
{
System.out.println("Hello Stars!");
}

public void secondMethod ()


{
System.out.println("Hello Saturn!");
}
}

public class Test


{
public static void main(String[] args)
{
Class2 c2 = new Class2();
c2.firstMethod();
c2.secondMethod();

Class3 c3 = new Class3();


c3.firstMethod();
c3.secondMethod();
}
}
Question 6 continues on the following page

__________________________________________________________________
Object Oriented Software Development COMP1307
Page 9 of 10
APPROVED

Question 6 continues

i. Predict the output when the program is run using java.

[3 marks]

ii. A specific behavioral design pattern has been used.

Identify the pattern.


[2 marks]

iii. State what the intent of this pattern is, and when such a pattern
should be used.
[5 marks]

c. A commonly employed design pattern is the Decorator pattern. Give a


code example of the use of the Decorator pattern as applied to objects
used in input or output, explaining what the code does and why the use
of this pattern is preferred to extension of classes by subclassing. (A
full program is not required – a program fragment of one or two lines
will suffice).
[10 marks]

_________________________________________________________________
Object Oriented Software Development COMP1307
Page 10 of 10

Potrebbero piacerti anche