/* * Created on Sep 13, 2004 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /** * @author oard * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class Library { Book[] books = new Book[3]; public Library(Book b1, Book b2, Book b3) { books[0]=b1; books[1]=b2; books[2]=b3; } public Book search(String title, String author, int year) { Book book = new Book(title, author, year); for (int i=0;i<3;i++) { if (book.equals(books[i])) { return books[i]; } } return null; } public static void main(String[] args) { Book tb1 = new Book("T1", "A1", 1991); Book tb2 = new Book("T2", "A1", 1991); Book tb3 = new Book("T3", "A1", 1991); Library library = new Library(tb1, tb2, tb3); Book result = library.search("T2", "A1", 1991); System.out.println("Found " + result.getTitle()); if (result.getAvailable()) { System.out.println("Hey great, it's available!!!!"); } result.checkOut(); if (result.getAvailable()) { System.out.println("Darn, it's still available!"); } else { System.out.println("OK -- the last copy is checked out."); } } }