Questions should be answered using code in Java, where appropriate, as the relevant ObjectOriented Language.
1. (a) Explain the concepts of inheritance and composition and discuss the benefits they bring
to object-oriented software engineering.
[6 marks]
(b) Explain what is meant by exception handling in modern programming languages and
outline how it is supported in Java. Why is programming language support for exceptions
important? What happens in languages without built-in support?
[9 marks]
(c) Implement a main program that emulates the throwing of a 6-side dice a number of times,
which the number of throws being a multiple of 6, and prints out the outcome. The number
of times the dice is thrown should be passed as an argument from the command line, not
obtained through the Scanner class. You should also make sure that the program warns
the user when an incorrect argument is passed to it and terminates gracefully but you do
not need to catch any exceptions. [15 marks]
2. (a) Explain the notions of array and linked list as key “collection” data structures in
programming languages. Present their advantages and disadvantages in terms of problem
size, element location and element addition. Consider both the case when elements are
kept without any order and also when they are kept sorted/ordered. [10 marks]
(b) Write a concatenate method for the List class. The concatenate method should take as
argument an external list object and merge it with the list instance variable, concatenating
the two lists.
[12 marks]
(c) Write first pseudo-code and then Java code for a getMiddleElement method of the List
class which should return a reference to the middle element of a list with an odd number
of elements. If the list has an even number of elements, the method should print an error
message and return a null reference.
[18 marks]
3. (a) What is a queue data structure? Explain how it can be implemented in two different ways
by re-using a more general data structure.
[7 marks]
(b) What is an OrderedList class and what is the difference in the methods it provides with
the plain List class? Assume we have an array of integer numbers which we would like
to sort in a relatively unorthodox manner by using an IntegerOrderedList class. Write an
arraySortThroughOrderedList method that converts an argument array to an integer
ordered list and then converts the list back to a sorted array.
[14 marks]
(c) Calculate the worst and best case complexity when searching for a given value in a binary
tree and state when each one these two conditions holds.
[9 marks]