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). A LetterQueue has a size, which determines the maximum number of letters it can contain.
The LetterQueue objects support the following functionalities:
null is returned;
null
is returned. The position in
the queue of a letter is equal to the number of letters that precede it in
the queue (e.g., the first letter in the queue has position 0, the following
one has position 1, etc.);Part 1. (20 points)
Realize a Java class LetterQueue
to represent LetterQueue
objects.
Solution:
representation of the
objects,
skeleton of the class,
class LetterQueue
Part 2. (6 points)
Realize a static method lettersShortRecipient
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.
Part 3. (4 points) Discuss the concepts of overloading and of overriding in Java. Give for both a short example.