Free University of Bozen-Bolzano
Faculty of Computer Science - Bachelor in Applied Computer Science
Introduction to Programming - A.A. 2005/2006

Exam exercise
Class Pier


We want to handle information relative to piers to which boats can be attached. Each boat is represented by its name (a string). A Pier has a code (a string) and a fixed number of boat positions, numbered sequentially starting from 0. Each boat position can be either free or occupied by a boat. The Pier objects support the following functionalities:

Part 1. Realize a Java class Pier to represent Pier objects.

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


Part 2. Realize a static method situationAtPier, client of the class Pier that, given a pier p, returns an array a of booleans, whose size is equal to the number of boat positions of pier p, and such that the value in position i of the array is equal to true if boat position number i of p is occupied by a boat, and false otherwise.

Solution


Part 3. Illustrate through examples the notions of overloading and of overriding, and how they are realized in Java.