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

Written Exam 30/1/2007

A library maintains books on various subjects.

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

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

Part 2. (16 points) For each topic (identified by its name, a string), the books on that topic available in the library shop are stored in a BookList data structure. Each book in a BookList is assigned a progressive number (an integer), starting from 0.

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

In the proposed solution, you have to take into account that there is no bound on the number of books that can be in a BookList. If you use arrays to represent a book list, you should handle the recovery of unused memory.

Part 3. (6 points) Realize a static method writeBooksByAuthor, client of the class BookList (i.e., external to such a class) that, given a BookList object bl, a string s (representing the name of an author), and the name f of a file, writes on the file f the title and authors of all those books in bl for which s appears among the authors, one book per line. The method should catch exceptions due to input/output errors that may occur, and print suitable error messages.

Part 4. (4 points) Discuss the notion of parameter passing in Java. Illustrate the difference between passing parameters of type (reference to an) object and of primitive types. Provide an example in which this difference becomes evident.