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

Exam exercise
Class PhotoGallery


We want to realize a Java class PhotoGallery that represents an online photo gallery. Each PhotoGallery has an url (represented by a string), and contains photos, each represented simply as a string that denotes the link to the actual photo. The maximum number of photos a photo gallery may contain is fixed the moment the photo gallery is created. The functionalities of the objects of the class are:


Part 1. Realize the class PhotoGallery.

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


Part 2. Realize a client class of the class PhotoGallery containing a static method readFromInput() that takes as parameter a PhotoGallery g, reads from standard input a set of photos (i.e., strings), one per line, stopping when the user inputs the empty string, and adds to g all photos read from input.

Solution


Part 3. Briefly discuss the difference between instance variables and local variables (with respect to initialization, lifetime, scope).