/** * A model a member of a library * * @author CSC 142 * */ public class LibraryMember { // A library member is identified by his/her ssn and // may have only one book private int ssn; private Book book; /** * Creates a library member given his/her ssn. Initially, the member doesn't * have a book. * * @param ssn * the social security number of the member */ public LibraryMember(int ssn) { this.ssn = ssn; book = null; // not needed, since already initialized to // null } /** * Borrows a book from the library given the title of the book. To borrow a * book, the member must not have a book already. * * @param title * the title of the book * @return true if the operation was successful, and false if not. */ public boolean borrowBook(String title) { if (book == null) { book = new Book(title); System.out.println("The book titled \"" + title + "\" has been checked out."); return true; } else { System.out.println("You can't check out another book.\n" + "You already have one."); return false; } } /** * Returns a book if there is one to return. * * @return true if the operation was successful, and false if not. */ public boolean returnBook() { if (book != null) { System.out.println("The book titled \"" + book.getTitle() + "\" has been returned."); book = null; return true; } else { System.out.println("You don't have any book to return."); return false; } } }