proj3
Class Library

java.lang.Object
  extended by proj3.Library

public class Library
extends java.lang.Object

Class Invariant:
Number of books and number of patrons are non-negative
and correctly indicate the number of books and patrons that are in the Library


Field Summary
static int MAX_COPIES
           
 
Method Summary
 java.lang.String addBook(java.lang.String title, int copies, java.lang.String authorFirst, java.lang.String authorLast)
          Preconditions: Number of copies must be positive, but not more than MAX_COPIES
One, but not both, of authorFirst and authorLast may be null
Postcondition: The book is added to the library and the number of books in the library is incremented
 java.lang.String addPatron(java.lang.String first, java.lang.String last)
          Preconditions: none
Postcondition: The patron is added to the list of patrons, the number of patrons in the library is incremented
and a library card number is assigned.
 java.lang.String checkOutBook(java.lang.String title, java.lang.String fName, java.lang.String lName)
          Preconditions: none
Postcondition: The book is checked out to the specified patron
 java.lang.String[] getAllBooks()
          Preconditions: none
 java.lang.String[] getAllPatrons()
          Preconditions: none
 java.lang.String getBook(java.lang.String title)
          Preconditions: none
 java.lang.String getPatron(java.lang.String fName, java.lang.String lName)
          Preconditions: none
 java.lang.String returnBook(java.lang.String title, java.lang.String fName, java.lang.String lName)
          Preconditions: none
Postcondition: The specified book is returned and available to be checked out again
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_COPIES

public static final int MAX_COPIES
See Also:
Constant Field Values
Method Detail

addBook

public java.lang.String addBook(java.lang.String title,
                                int copies,
                                java.lang.String authorFirst,
                                java.lang.String authorLast)
Preconditions: Number of copies must be positive, but not more than MAX_COPIES
One, but not both, of authorFirst and authorLast may be null
Postcondition: The book is added to the library and the number of books in the library is incremented

Parameters:
title - - the title of the book to add to the library
copies - - the number of copies of the book added to the library
authorFirst - - the author's first name (may be null)
authorLast - - the author's last name (may be null)
Returns:
- A message indicating whether or not the book was added to the library.
Duplicate titles are not permitted.

addPatron

public java.lang.String addPatron(java.lang.String first,
                                  java.lang.String last)
Preconditions: none
Postcondition: The patron is added to the list of patrons, the number of patrons in the library is incremented
and a library card number is assigned.

Parameters:
first - - the first name of the patron to add (may not be null)
last - - the last name of the patron to add (may not be null)
Returns:
- a message indicating whether or not the patron was added.
If the patron was not added, the message must indicate why not.
Duplicate patrons are not permitted.

checkOutBook

public java.lang.String checkOutBook(java.lang.String title,
                                     java.lang.String fName,
                                     java.lang.String lName)
Preconditions: none
Postcondition: The book is checked out to the specified patron

Parameters:
title - - the title of the book to be checked out
fName - - the first name of the patron who wishes to check out the book
lName - - the last name of the patron who wishes to check out the book
Returns:
- A string indicating that the book was successfully checked out
or a string indicating why the book was not checked out.
Return messages should include all relevant information

getAllBooks

public java.lang.String[] getAllBooks()
Preconditions: none

Returns:
an array of strings containing the titles and authors of all books in the library.
One book and its author per string.
If there are no books in the library, return a message indicating so.
Book title must be in double quotes
Author's name must be last name first.

getAllPatrons

public java.lang.String[] getAllPatrons()
Preconditions: none

Returns:
- an array of strings each containing a patrons library card number and name, last name first.
If there are no patrons in the library, a message to that effect must be returned.

getBook

public java.lang.String getBook(java.lang.String title)
Preconditions: none

Parameters:
title - - the title of the book
Returns:
- If the book exists, a multi-line string which includes the book's title and author
and the library card number and name of the patron (last name first) who currently has the book checked out.
If the book is not checked out, the message should so indicate
If the book does not exist, an appropriate error message is returned

getPatron

public java.lang.String getPatron(java.lang.String fName,
                                  java.lang.String lName)
Preconditions: none

Parameters:
fName - - the first name of the patron whose information should be returned
lName - - the last name of the patron whose information should be returned
Returns:
- If the patron exists, a multi-line string which includes the patron's
library card number and name (last name first) and the
titles of all books currently checked out by the patron is returned
If the patron does not exist, an appropriate error message is returned

returnBook

public java.lang.String returnBook(java.lang.String title,
                                   java.lang.String fName,
                                   java.lang.String lName)
Preconditions: none
Postcondition: The specified book is returned and available to be checked out again

Parameters:
title - - the title of the book being returned
fName - - the first name of the patron returning the book
lName - - the last name of the patron returning the book
Returns:
- A string indicating that the book was successfully returned
or a string indicating why the book was not returned.