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

Exam exercise
Class Counter


The municipality needs a system to handle the queues at their offices. At the counter, persons in need of documents from the offices can get a unique, progressive number that defines their position in the queue. The requests are handled according to this number.


Part 1. Realize a class Request with the following attributes:

The class should export the following functionalities:

Solution: skeleton of the class, class Request


Part 2. Realize a class Counter, each of whose objects stores a queue of requests issued at the counter. The maximum number of requests that can be in the queue is determined the moment a counter is created. The class should export the following functionalities:

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


Part 3. Implement a client class for Counter that contains a static method readFromInput() that, given a Counter c:

  1. reads from standard input an integer n and then n names of persons, one per line,
  2. adds for each person read from input a request to counter c, and
  3. returns an array containing the progressive numbers associated to the requests.

Solution


Part 4. Explain how objects are allocated in a Java program, and when and how the memory occupied by an object is again made available for other objects.


Note: You can test the code you have developed by using the class defined in the file Main.java and redirecting standard input from the example file paperopoli.txt (containing the italian names of Disney comic book characters) as follows:

C:\> java Main < paperopoli.txt