CMSC 341 Project 1

Spring 2013

Project 1

Assigned February 20

Revised February 21

Revised February 27

Due by 11:59pm, March 3, 2013

Using Lists of Lists

In this project, you will create a simple library circulation management system. A library has a number of patrons, each of which has a five digit ID number. The library's holdings are books, identified by their titles. You can make the (unrealistic) assumptions that titles are unique, and that the library holds only one copy of each title. The titles are given as character strings.

Patrons can borrow and return titles, and can request a list of what they've borrowed. The library can also find out which patron has borrowed a given title. Waiting lists can exist for popular books. The library can get a list of patrons who have ever borrowed a book, even if they have nothing checked out at the moment.

The commands are in the following format:

patronID borrow title
patronID return title
patronID list
whohas title
waitlist title

Where patronID is an integer and title is a quoted String. The commands are found in a simple text file, the pathname of which is passed to your program as a command line argument. You can assume that the input is in the correct format, and you are free to use the scanner class to parse the input file.

You are encouraged to make your own test file while developing your program. The TAs will have a separate test file, which might not be made public. Examples of commands:

31416 borrow "Gone with the Wind"
31416 return "Gone with the Wind"
31416 list
whohas "Gone with the Wind"
waitlist "Gone with the Wind"

If a patron tries to borrow a book that has not been borrowed before, you can assume the library in fact has that book available.

If patron X tries to borrow a book that some other patron Y has already borrowed and not yet returned, patron X will join a (possibly empty) first-in first-out queue of patrons that are waiting for that same book. When that book is returned, the next patron in the queue (which may or may not be X) will borrow it automatically. The waitlist command shows the list of patrons waiting for a specific title, with the next patron to get the book listed first. If the list is empty, waitlist should issue an appropriate message.

If a patron tries to return a book that is not on the list of materials they have borrowed, the return command should check for this and print an appropriate message.

A patron's list of borrowed titles may be empty, and an appropriate message printed in this case.

If no patron has checked out a given title, then the whohas command will indicate this.

The patron list starts out empty. A patron joins the list the first time they attempt to borrow or return something.

You will need to keep a LinkedList of Patrons. You are welcome to use the LinkedList class provided in the Java API. Do not use any built-in classes for queues that Java might provide. Your program will define public classes Patron and Book. You may find it convenient to create additional methods for testing.

You are required to use Iterators as appropriate to access the lists you use in your program.

The public Patron class will provide the following methods:

void PatronBorrow(String)  // to borrow a book
void PatronReturn(String)  // to return a book
void PatronList()          // print a list of books borrowed, one per line

The public Book class will provide the following methods:

void addToQ(Patron)   // to add a patron to this book's waiting list
boolean emptyQ()      // TRUE if and only if waiting list is empty
Patron removeFromQ()  // to get the next patron from the waiting list
void printQ()         // to print this book's waiting list, one patron per line

You are welcome to do more error checking than is required by this specification, and we reserve the right to award extra credit in these cases. You can, for example define exceptions to be thrown and caught.

You will need to prepare a README file. In this file, please describe the execution time complexity of the six commands described above. For each command, under what circumstances would you expect the worst-case performance to occur?

The CVS repository for this project is /afs/ You will need to commit five files:,,, build.xml and README.

Suppose you have test data in a file called commands.txt. To run your program using ANT from the command line, you'll need to pass this file name to your program as a command-line argument. The command to do this is

ant -Dargs="commands.txt" run 

In Eclipse, use the Run -> Run Configurations menu. In the arguments window, enter the name of the data file.

Sample output: Your output does NOT have to match this format exactly.

12345 borrow "Gone with the Wind"
Patron 12345 has borrowed "Gone with the Wind"
whohas "Gone with the Wind"
Patron 12345 has "Gone with the Wind"
27182 borrow "Gone with the Wind"
Patron 27182 is waiting for "Gone with the Wind"
31416 borrow "Gone with the Wind"
Patron 31416 is waiting for "Gone with the Wind"
waitlist "Gone with the Wind"
Patron(s) waiting for "Gone with the Wind":
12345 return "Gone with the Wind"
Patron 12345 has returned "Gone with the Wind"
Patron 27182 has borrowed "Gone with the Wind"
27182 list
Patron 27182 has borrowed 1 item(s):
"Gone with the Wind"
Patrons include: