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:
getPerson that returns the person's name;
getNumber that returns the progressive number;
toString that allows to get a String representation
of a request object.
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:
addRequest that, given a person's name appends a
new request to the counter's queue and returns the progressive number
associated to this request;
handleRequest that gets the next request from the
queue; if there are no requests left an exception should be thrown;
giveUp that, given a progressive number eliminates the
corresponding request from the queue;
if there is no such request, an exception is thrown;
waitingTime that, given a progressive number
computes the number of requests that are queued before that request; if
there is no such request, throw an exception;
toString that returns a string representation of
the request object.
addRequest is called to append
one more request, create a new array double the size of the old one and
copy the old array's content into the new one;
handleRequest, create a new array half the size of the old
one and copy the old array's content into the new one;
Solution: Counter.java, CounterException.java
Exercise 11C
Implement a client class forCounter that acts as follows:
Counter;
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): paperopoli.txt
Note: to open a file specify its absolute path (for
example C:\java-projects\lab-11\paperopoli.txt) since BlueJ does
not set the current directory path.
Solution: Client.java