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

Exercise 11

Dynamic Arrays


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.


Exercise 11A

Implement a class Request with the following attributes:

The class should implement the following features:

Solution: Request.java


Exercise 11B

Implement a class Counter that stores a queue of all requests issued at the counter.

The class should implement the following features:

Hint: implement the queue using a dynamic array:

Solution: Counter.java, CounterException.java


Exercise 11C

Implement a client class for Counter that acts as follows:
  1. create an initially empty Counter;
  2. have the user input the name of a text file containing person's names (one name for each line); for each person add a request to the counter's queue;
  3. ask the user repeatedly which of the following actions should be taken and perform them: after each operation print out the queue.
The client should catch the exceptions thrown by Counter printing a warning message, but without terminating the program.

Here is an example input file (it contains the italian names of Disney comic book characters): disney.txt

Note: to open a file specify its absolute path (for example C:\java-projects\lab-11\disney.txt) since BlueJ does not set the current directory path.

Solution: Client.java