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

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 reads from standard input an integer c and then c/2 floats, and returns a Buffer object with initial capacity c and containing as data items the floats read from standard input in the order in which they are read. Before each read operation an appropriate message should be printed on standard output.

Solution


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