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

Exam exercise
Class Buffer


A Buffer is an object that represents a zone of memory that temporarily stores data items. For simplicity, we assume that each data item is a float. A Buffer has a limited capacity, corresponding to the number of data items it can store. Buffer objects support the following functionalities:


Part 1. Write a Java class Buffer to represent Buffer objects.

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


Part 2. Realize a static method client of the class Buffer that, given a string f that represents the name of a file containing a line with an integer c and a certain number of successive lines each containing a float, returns a Buffer object with initial capacity c and containing as data items the floats present in the file in the order in which they are read from the file.

Solution


Part 3. Describe the notions of local variable and of instance variable, and illustrate specifically the concepts of scope and lifetime.