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

Written Exam 8/2/2006

A parcel delivery service needs to manage parcels that have to be sent to various countries. For a country (identified by its name, a string), the sequence of parcels to be sent to the country are stored, in the order in which they have to be sent, in a ParcelsToSend data structure. Each parcel in the ParcelsToSend data structure is represented simply by a string (denoting the address to which the parcel has to be sent). A ParcelsToSend object has a size, which determines the maximum number of parcels it can contain.

The ParcelsToSend objects support the following functionalities:

Part 1. (20 points)

Realize a Java class ParcelsToSend to represent ParcelsToSend objects.

Solution: representation of the objects, skeleton of the class, class ParcelsToSend, class ParcelsException

Part 2. (6 points) Realize a static method getParcelsByAddress client of the class ParcelsToSend (i.e., external to such a class) that, given a ParcelsToSend object ps, a string s, and the name f of a file, writes to the file f the position in the sequence and the address string for all those parcels for which the address string starts with s, one parcel 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.