Free University of Bozen-Bolzano
Faculty of Computer Science - Bachelor in Applied Computer Science
Introduction to Programming - A.A. 2004/2005
(old study plan - 6 CFU)

Written Exam 2/2/2005

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, class LetterQueueException

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. The method should handle exceptions due to input/output errors that may occur.

Solution

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