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

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.

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 and a string s, writes to standard output 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.

Part 3. (4 points)

Discuss the concepts of scope and of lifetime of variables, and point out the difference between local variables and instance variables.