Module Examination 2013 Object Oriented Java Programming
Module Examination 2013 Object Oriented Java Programming
M250/E
Module Examination 2013
This exam contains four questions worth 25 marks each. You should
attempt ALL questions.
All your answers must be written in the answer book(s) provided. You
should start each of the four questions on a new page. Indicate which
questions you have attempted in the spaces provided on the front cover.
You are advised not to cross through any work until you have replaced it
with another solution to the same question.
There are no marks awarded for commenting your code and you may
assume any import statements required, unless otherwise indicated.
You may assume that methods receive sensible values when a
message is sent unless otherwise indicated.
At the end of the examination
Check that you have written your personal identifier and examination
number on each answer book used. Failure to do so will mean that
your work cannot be identified.
Put all your used answer books together with your signed desk record
on top. Fasten them in the top left corner with the round paper fastener.
Attach this question paper to the back of the answer books with the flat
paper clip.
With reference to the above statements only, identify the lines of code
(state "none" if there are no such lines) in which
(i) reference variables are declared
(ii) primitive variables are declared
(iii) objects other than strings are created
(iv) arguments are passed to methods
(v) messages are sent
(vi) Boolean values are used
(vii) constructors are invoked
(7 marks)
10 "Sparky"
200 "BrightGuy"
911 "Neverlast"
42 "Blinker"
Table 1 Catalogue of model numbers and names for light bulbs
Suppose that in a piece of software under development these tables are
implemented and managed by instances of a class called BulbCatalogue.
(a) The class BulbCatalogue needs a single private instance variable called
catalogue. Write down the declaration for catalogue, which should be
declared to be of a suitable interface type to hold an unsorted map with the
model number as the key.
(3 marks)
(b) Write a zero-argument constructor for BulbCatalogue that initialises
catalogue to reference an empty map of an appropriate class.
(3 marks)
(c) Write a public instance method called populateCatalogue() for the
BulbCatalogue class that takes no arguments and returns no value. This
method should simply add the four entries shown in Table 1 to the map
referenced by catalogue.
(2 marks)
(d) Write a public instance method for the BulbCatalogue class called
updateCatalogue() that takes no arguments and returns no value. This
method should update the model name for any model number in the map
less than 100 by appending the text " – economy" (as illustrated in Table 2
below). Your method should work irrespective of how many entries there are
in the map referenced by catalogue.
10 "Sparky – economy"
200 "BrightGuy"
911 "Neverlast"
42 "Blinker – economy"
Table 2: After the method updateCatalogue() has been executed
(7 marks)
Token
try
{
bufferedFileWriter = //complete for part (a)(iii)
}
catch (IOException anException) //discuss in (c)(iv)
{
System.out.println("Error: " + anException);
}
finally
{
try
{
bufferedFileWriter.close();
}
catch (Exception anException)
{
System.out.println("Error: " + anException);
}
}
}
(a) With reference to the commented lines in the code above and making use of
appropriate library classes from your Exam Handbook:
(i) Complete the assignment statement that begins:
String pathName =
(1 mark)
(ii) Complete the assignment statement that begins:
File amphibianFile =
(1 mark)