A post office needs to keep track of letters that have to be delivered to various cities. For each city (identified by its name, a string), the letters to be delivered to that city are stored, in the order of delivery, in a LetterQueue data structure. Each letter in the LetterQueue is represented simply by a string (denoting the name of the recipient).
The LetterQueue objects support the following functionalities:
Part 1. (20 points)
Realize a Java class LetterQueue
to represent LetterQueue
objects. In the proposed solution you have to take into account that there is
no bound on the number of letters that can be in a LetterQueue. If
you use arrays to represent the collection of letters, you should handle the
recovery of unused memory.
Solution:
representation
of the objects,
skeleton of the class,
class LetterQueue
,
class
LetterQueueException
Part 2. (6 points)
Realize a static method lettersShortString
client of the class
LetterQueue
(i.e., external to such a class) that, given a
LetterQueue
object q, a positive integer len,
and the name f of a file, writes on the file f the position
in the queue and the string (i.e., the name of the recipient) for all those
letters for which the string is shorter than len, one letter per line.
The method should handle exceptions due to input/output errors that may occur.
Part 3. (4 points) Discuss the concepts of overloading and of overriding in Java. Give for both a short example.