Free University of Bozen-Bolzano
Bachelor in Production Engineering
Introduction to Programming - A.A. 2005/2006

Exam exercise (adapted from Exam of 2/2/2005)
Class LetterQueue

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:

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, and a positive integer len, writes to standard output 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.

Solution

Part 3. (4 points) Discuss the concepts of overloading and of overriding in Java. Give for both a short example.