Module Examination 2014 Object-Oriented Java Programming: Thursday, 5 June 2014 2:30 PM - 5:30 PM Time Allowed: 3 Hours
Module Examination 2014 Object-Oriented Java Programming: Thursday, 5 June 2014 2:30 PM - 5:30 PM Time Allowed: 3 Hours
M2501406F1
M250/F
Module Examination 2014
OBJECT-ORIENTED JAVA
PROGRAMMING
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.
Explain why this code will not compile and how you could fix it.
(2 marks)
Question 2 (a) Suppose that Feedable is an interface that specifies a single instance
(25 marks) method with the name feed(). This method takes no argument and returns
a value of either true or false. Write down the Feedable interface.
(2 marks)
(b) Suppose that HungryFrog is a subclass of the OU library class Frog and
that HungryFrog implements the Feedable interface.
(i) Write down the header for the HungryFrog class.
(ii) Instances of HungryFrog have an additional instance variable
energyLevel which is declared to be of type int and accessor
methods for getting and setting the value of this instance variable.
When an instance of HungryFrog is first created, its energy level is
initialised to a class constant FULL, which has the value 2000 (every
hungry frog starts life with a full stomach). Inherited instance variables
in instances of HungryFrog are to be initialised to the same state as in
instances of Frog.
Write a zero-argument constructor for HungryFrog.
Your method should assume that the bulb type exists as a key in the
map.
(3 marks)
(vii) Write a public instance method printCatalogue() that takes no
arguments and returns no value. The method prints to standard output
each bulb type and its varieties. The output should be of the form:
Catalogue:
}
}
catch (IOException anException)
{
System.out.println("Error: " + anException);
}