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

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 class should export the following functionalities:

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


Part 3. Implement a client class for Counter that contains a static method readFromFile that, given a string f that represents the name of a file containing names of persons, one per line, and a Counter c, adds for each person in the file a request to counter c, and returns an array containing the progressive numbers associated to the requests.

Solution



Part 4. Illustrate the mechnism of error handling in Java through exceptions.


Note: test the code you have developed by using the class defined in the file Main.java and the example file paperopoli.txt (containing the italian names of Disney comic book characters).