Class Library

java.lang.Object
  |
  +--Library

public class Library
extends java.lang.Object

Library class, not instantiated, all static methods for one library. Date started 2004.Oct.26 Part of Blab2.java (Second = 035B Java college-class, lab assignment #2)

Author:
Robert Elton Maas

Field Summary
private static java.util.Vector books
           
private static boolean changed
           
private static java.util.Calendar datime
           
private static java.lang.String fn
           
 
Constructor Summary
Library()
           
 
Method Summary
static void addBook(int id, java.lang.String title, java.lang.String author, java.lang.String isbn)
          Given that all fields verified valid, make new book record and add it to the library's collection.
static java.util.Enumeration allBooks()
           
static void authorSortList(java.lang.String key)
          Given key (part of author name), find all books by such athors, and print full info about each.
static Book2 bookAtIndex(int ix)
          Given index in list of books, retrieve full Book2 record
static int bookDueDiff(Book2 bk)
           
static int bookDynamicFine(Book2 bk)
          Compute dynamic fine for one book
static boolean checkOutBook(int ix, Patron pt)
          Make sure book is currently in the library, and assuming that, check it out, setting due date in 3 days.
static boolean confirmFullword(java.lang.String question)
          Similar to yes-or-no-p in CL, asks a question and expects full word yes or no as the answer.
static int findById(int id)
          Search for a book with given ID.
static int findByIsbn(java.lang.String isbn)
          Search for a book with given ISBN.
static int findByTitle(java.lang.String title)
          Look for any book by specified title, complain if more than one (and show first two).
static void markChanged()
          Mark the library database as changed, so it'll be saved upon exit.
private static void matchesSortList(java.util.Vector match)
          Common code for author/title search.
static void mayLoadBooksDatabase()
          If library database exists, load it, else ask user if it's OK to start with empty database.
static void maySaveBooksDatabase()
          If any changes since last save/restore, save entire books database to disk file.
static java.util.Enumeration overdueBooks()
           
static boolean removeBook(int ix)
          Delete record of book from the library database
static void renewBook(java.util.Calendar due, int ndays)
          Renew a book
static void reserveBook(int ix, Patron pt)
          Reserve a book
static boolean returnBook(int ix)
          Make sure book was checked out, and assuming that, check it back in.
static void titleSortList(java.lang.String key)
          Given key (part of title), find all books with such titles, and print full info about each.
static void updateDatime(int ndays)
          If datime is not yet the current date&time, make it so.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

books

private static java.util.Vector books

changed

private static boolean changed

fn

private static final java.lang.String fn

datime

private static java.util.Calendar datime
Constructor Detail

Library

public Library()
Method Detail

authorSortList

public static void authorSortList(java.lang.String key)
Given key (part of author name), find all books by such athors, and print full info about each.

titleSortList

public static void titleSortList(java.lang.String key)
Given key (part of title), find all books with such titles, and print full info about each.

matchesSortList

private static void matchesSortList(java.util.Vector match)
Common code for author/title search. Given list of matching Book2 records, sort, and print info about each.

markChanged

public static void markChanged()
Mark the library database as changed, so it'll be saved upon exit.

reserveBook

public static void reserveBook(int ix,
                               Patron pt)
Reserve a book
Parameters:
ix - int index of book in list of books
pt - Patron full record of patron who wants to reserve this book

renewBook

public static void renewBook(java.util.Calendar due,
                             int ndays)
Renew a book
Parameters:
due - Calendar The due-date which is part of the Book record
ndays - int The number of days to renew the book

bookAtIndex

public static Book2 bookAtIndex(int ix)
Given index in list of books, retrieve full Book2 record
Parameters:
ix - int Index
Returns:
Book2 Full Book2 record at that index

returnBook

public static boolean returnBook(int ix)
Make sure book was checked out, and assuming that, check it back in.
Parameters:
ix - Index where book was found in vector books.
Returns:
True if operation was successful.

overdueBooks

public static java.util.Enumeration overdueBooks()
Returns:
An emumeration of only the overdue books

bookDueDiff

public static int bookDueDiff(Book2 bk)
Returns:
int Negative number if overdue up to that many days, zero if book will be due during the very next 24 hours, positive number if not due until at least n days plus fraction ignored.

bookDynamicFine

public static int bookDynamicFine(Book2 bk)
Compute dynamic fine for one book
Parameters:
bk - Book2 The full book record of the book
Returns:
int The current dynamic fine for book if overdue, else 0

allBooks

public static java.util.Enumeration allBooks()
Returns:
An enumeration of all the books in the library

findByTitle

public static int findByTitle(java.lang.String title)
Look for any book by specified title, complain if more than one (and show first two).
Parameters:
title - The title or a substring thereof
Returns:
The index in vector books where the unique match was found, -1 if no/dup match.

checkOutBook

public static boolean checkOutBook(int ix,
                                   Patron pt)
Make sure book is currently in the library, and assuming that, check it out, setting due date in 3 days.
Parameters:
ix - Index where book was found in vector books.
Returns:
True if operation was successful.

addBook

public static void addBook(int id,
                           java.lang.String title,
                           java.lang.String author,
                           java.lang.String isbn)
Given that all fields verified valid, make new book record and add it to the library's collection.
Parameters:
id - Library's ID number for book.
title - Title of book.
author - Name of author of book.
isbn -  

findById

public static int findById(int id)
Search for a book with given ID.
Parameters:
id - Library's ID for book
Returns:
If found, the index where found, else -1.

findByIsbn

public static int findByIsbn(java.lang.String isbn)
Search for a book with given ISBN.
Parameters:
isbn -  
Returns:
Index where found, or -1 if not found.

updateDatime

public static void updateDatime(int ndays)
If datime is not yet the current date&time, make it so. After that, if ndays > 0, fudge datime forward by that many days.
Parameters:
ndays - Number of days to fudge from current date&time

confirmFullword

public static boolean confirmFullword(java.lang.String question)
Similar to yes-or-no-p in CL, asks a question and expects full word yes or no as the answer.
Parameters:
question - Question to ask the user.
Returns:
True if user said YES, false if user said NO.

removeBook

public static boolean removeBook(int ix)
Delete record of book from the library database
Parameters:
ix - Index where book was found in vector books.

mayLoadBooksDatabase

public static void mayLoadBooksDatabase()
If library database exists, load it, else ask user if it's OK to start with empty database.

maySaveBooksDatabase

public static void maySaveBooksDatabase()
If any changes since last save/restore, save entire books database to disk file.