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

Written Exam 28/6/2005

A company manufacturing bicycles needs to keep track of its bikes that are being sold in various shops.

Part 1. (4 points) For each Bike object, the information of interest is:

Realize a Java class Bike, to represent Bike objects, that exports the following functionalities:

Solution: class Bike

Part 2. (16 points) For each shop (identified by its name, a string), the bikes available in that shop are stored in a BikePool data structure. A BikePool has a size, which determines the maximum number of bikes it can contain.

Realize a Java class BikePool, to represent BikePool objects, that exports the following functionalities:

Solution: representation of the objects, skeleton of the class, class BikePool

Part 3. (6 points) Realize a static method ColorsforWeight, client of the class BikePool (i.e., external to such a class) that, given a BikePool object bp, a positive integer h representing the weight of a person, and the name f of a file, writes on the file f the colors of all those bikes in bp that are suitable for weight h.

Solution

Additional files to test the solution: class Main, input file bikes.txt

Part 4. (4 points) Discuss the notions scope and of lifetime of a variable. Emphasize the differences with respect to scop and lifetime between the different types of variables that a Java program may contain.