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

Exam exercise (adapted from Exam of 28/6/2005)
Class BikePool

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, and a positive integer h representing the weight of a person, writes to standard output the colors of all those bikes in bp that are suitable for weight h.

Solution

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

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