Você está na página 1de 11

DESIGNING AND DEVELOPING

OBJECT-ORIENTED
COMPUTER PROGRAMS

11
TH
MARCH 2012

MARKING SCHEME


This Marking Scheme has been prepared as a guide only to markers. This is not a set of model
answers, nor is the Marking Scheme exclusive, for there will frequently be alternative responses
which will provide a valid answer. Unless a question specifies that an answer be produced in a
particular form, then an answer that is correct, factually or in practical terms, must be given the
available marks.

If there is doubt as to the correctness of an answer the relevant NCC Education materials and
associated module textbook should be the first authority.




Throughout the question, please credit any valid alternative point.


Notice to Markers

Where markers award half marks in any part of a question they should ensure that the total
mark recorded for a task is rounded up to a whole mark.




QUESTIONS CONTINUE ON NEXT PAGE
Page 2 of 11

Designing and Developing Object-Oriented Computer Programs March 2012 Formatted/HW NCC Education Ltd 2012

ANSWER ALL QUESTIONS


QUESTION 1

Marks
a) Explain what purpose the main method in a J ava program serves, and provide the code for a
main method that creates an instance of the class in which it is contained.
6
The main method is the starting point of a java program (1 mark) and is the method that java
will look for when a program is executed (1 mark). 4 marks for the example which should
include the correct method signature of the main method (2 marks) and the correct code for
creating an instance of its container class (2 marks)


b) Explain what is meant by primitive data type and reference data type, and give an example
of each.
4
Primitive data types are the building blocks of data representation and are provided by the
language (1 mark). Reference data types are instances of objects, although some of them are
also handled by java keywords (1 mark). An int is a primitive data type (1 mark), while a
String is a reference data type (1 mark).

Total 10 Marks

QUESTIONS CONTINUE ON NEXT PAGE
Page 3 of 11

Designing and Developing Object-Oriented Computer Programs March 2012 Formatted/HW NCC Education Ltd 2012

Marks
QUESTION 2

a) Define the words Class and Object, and explain the relationship between them. 4
A class defines the methods and variables for a particular class of object (1 mark) and an
object defines the state of those variables (1 mark). An object is an instantiation of a class (1
mark), and the class acts as the blueprint for the object (1 mark).

b) Explain what is meant by an event, and outline what is required for a J ava program to make use
of them.
6
An event is a non-typical occurrence in a programs lifecycle (1 mark). When the user
interacts in some way with a Java program, an event will be generated (1 mark), and
information about that event will be sent to all interested listener objects (1 mark). In order
for a java program to use the event, it must first implement the required listener methods (1
mark), register itself as a listener for that kind of event (1 mark), and then implement the
handling code (1 mark).

Total 10 Marks


QUESTIONS CONTINUE ON NEXT PAGE
Page 4 of 11

Designing and Developing Object-Oriented Computer Programs March 2012 Formatted/HW NCC Education Ltd 2012



QUESTION 3

Marks
a) Define the term encapsulation and give an example of its use. 5
Encapsulation is a feature of data-centric languages, and involves the packaging of data (1
mark) along with the methods that act on that data (1 mark). Encapsulation also often
implies a black box design of methods (1 mark). 2 marks for a suitable example.

b) Define the term inheritance in the context of object oriented programming and give an example
where it could profitably be used.
5
Inheritance is the programming process whereby one object gains a copy of anothers
methods and variables (2 marks) so as to ensure reusability (1 mark). 2 marks for a suitable
example.


Total 10 Marks


QUESTIONS CONTINUE ON NEXT PAGE
Page 5 of 11

Designing and Developing Object-Oriented Computer Programs March 2012 Formatted/HW NCC Education Ltd 2012



QUESTION 4

Marks
a) Define what is meant by a strongly typed language and explain what benefits strong typing
provides for software developers.
4
Strongly typed languages limit how variables of different data types can be intermixed (1
mark), ensuring that invalid operations are caught as early as possible (1 mark). Benefits
include finding errors earlier in the development process (1 mark), and the ability of the
compiler to generate meaningful errors (1 mark).

b) Assume you are given an array of the numbers 30, 50, 20 and 10. Outline the process by which
you could generate a bar chart from this data.
6
Assuming a fixed origin of 0,0 (the top left), we would get the size of the users screen and
find where the bottom left was located relative to the origin (1 mark). We would then define
the width and height of our bars based on a proportion of the users screen (1 mark), and
draw the bars of equal width but of a height indicated by the numbers we have (1 mark). For
each bar, we move to the right a number of pixels equal to the width of the bar we decided
upon (1 mark). Drawing the bars themselves is handled by fillRect (1 mark), and the labels
underneath or over the bars would be handled by drawString (1 mark).

Total 10 Marks

QUESTIONS CONTINUE ON NEXT PAGE
Page 6 of 11

Designing and Developing Object-Oriented Computer Programs March 2012 Formatted/HW NCC Education Ltd 2012

Marks
QUESTION 5

a) Give TWO (2) examples of Swing components, and explain for what purposes they might be
used.
4
Any swing components are valid here, such as JTextArea and JScrollBar. One mark for each
component, and one mark for the explanation of the components purpose.


b) Explain the role of a layout manager in setting up a user interface in J ava, and why they are
preferable to manual positioning.
6
Layout managers handle the automatic laying out of GUI components (1 mark) according to
some rigorous regime (1 mark). Layout managers can be set on a frame or panel (1 mark),
and combinations of panels and layout managers permit for sophisticated layouts (1 mark).
Layout managers are more sophisticated than manually positioning (1 mark) because they
preserve relationships, proportionality and sizing across applications when their dimensions
are manipulated (1 mark).

Total 10 Marks
J


QUESTIONS CONTINUE ON NEXT PAGE
Page 7 of 11

Designing and Developing Object-Oriented Computer Programs March 2012 Formatted/HW NCC Education Ltd 2012


Marks
QUESTION 6

a) Explain the purpose of UML, and what benefits accrue from adopting it in software engineering. 4
UML is a diagramming notation (1 mark) and is used to communicate between involved
parties in development (1 mark). Benefits include front-loading design issues (1 mark) and
the ease with which designs can be translated into code (1 mark).


b) Define two kinds of UML diagram, and explain what role they fulfil. Provide examples of the
diagrammatic notation of each.
6
Any two diagrams would be suitable for this 1 mark for identifying the diagrams, 1 mark for
the roles, and 1 mark for drawing the diagram.

Total 10 Marks

QUESTIONS CONTINUE ON NEXT PAGE
Page 8 of 11

Designing and Developing Object-Oriented Computer Programs March 2012 Formatted/HW NCC Education Ltd 2012


Marks
QUESTION 7

a) Explain what is meant by defensive programming. 4
Defensive programming is the tactic of writing code to reduce future, unanticipated problems
(1 mark). It can be done by reducing code complexity (1 mark), ensuring data consistency
throughout all operations in a program (1 mark), and treating all input from the user as
potentially tainted and thus in need of validation (1 mark).


b) Explain what is meant by an exception. 2
An exception indicates that an exceptional event has occurred during the running of a java
program (1 mark), and indicates that an error has been encountered that could not be
foreseen at compile-time (1 mark).

c) Provide a code example of a try-catch-finally block, explaining the responsibilities of each part
of the structure.
4
try {
// Some expression
}
Catch (SomeException) {
}
Finally {
}

1 mark for the code, and up to 3 marks for explaining what each part of the structure is
supposed to do.


Total 10 Marks







QUESTIONS CONTINUE ON NEXT PAGE
Page 9 of 11

Designing and Developing Object-Oriented Computer Programs March 2012 Formatted/HW NCC Education Ltd 2012


Marks
QUESTION 8

a) Provide code examples of the getter and setter for an integer variable called value, and explain
why getters and setters are used in OO programming.
6
2 marks each for the getter and the setter. Justifications should include the need for
encapsulation (1 mark) and the need for controls to be placed around the manipulation of
data elements so as to ensure consistency (1 mark).


b) Explain what is meant by the term visibility and give TWO (2) examples of visibility modifiers
in J ava.
4
Visibility refers to how generous a program is with when a variable or method can be invoked
(1 mark). The higher the visibility, the more objects can make use of the internal code of
other objects (1 mark). Public is the highest visibility (1 mark), and private the lowest (1
mark).

Total 10 Marks



QUESTIONS CONTINUE ON NEXT PAGE
Page 10 of 11

Designing and Developing Object-Oriented Computer Programs March 2012 Formatted/HW NCC Education Ltd 2012


Marks
QUESTION 9

a) Explain what is meant by a two dimensional array, and give an example of where one might be
appropriate.
4
A two dimensional array is one that has both length and height and each compartment is
indicated by a pair of integers (1 mark). It is best used for storing grids of data as opposed to
tables of data (1 mark). 2 marks for a suitable example.


b) One of the limitations of a standard array is that its length is fixed. State a data structure that can
be used to give the benefits of an array without this limitation, and provide a code example in
which an array and your suggested data structure perform the same duty.
6
An ArrayList would be an appropriate data structure (1 mark) as it is functionally identical to
an array except that it dynamically resizes (1 mark). For the example, 2 marks are available
for showing a scenario using an array, and another 2 for showing the same scenario using
the students suggested data type.

Total 10 Marks

END OF EXAM
Page 11 of 11

Designing and Developing Object-Oriented Computer Programs March 2012 Formatted/HW NCC Education Ltd 2012


Marks
QUESTION 10

a) Explain what is meant by a stream in terms of input/output, and give an example where you
have previously used streams in the module.
4
A stream is a form of I/O in which all data is received in sequence (1 mark) and in one
direction (1 mark). 2 marks for a suitable example.


b) Explain the phrase buffering, and why we should ensure we use BufferedReaders and
BufferedWriters when constructing our file access routines.
6
Buffering refers to the process of waiting until we have enough read or write operations
pending to justify the overhead of file I/O (2 marks). We should use BufferedReaders and
BufferedWriters because file I/O is usually the performance bottleneck in a program (2 mark)
and by reducing the overhead required to make a file operation we can have much more
efficient computer programs (2 marks).

Total 10 Marks