/** * A simple model of a member of a library * * @author CSC 142 * */ public class LibraryMember { // A library member is defined by his/her ssn // and can have at most 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 book is // automatically initialized to null } /** * Borrows a book given the title of the book. The operation is successful * only if the member didn't have a book * * @param title * the title of the book to borrow. * @return true if successful, or false if not */ public boolean borrowBook(String title) { if (book == null) { // the member doesn't have a book // and can borrow one. book = new Book(title); System.out.println("The book titled " + title + " has been borrowed."); return true; } else { // the member can't borrow another book System.out .println("You can't borrow this book.\nYou already have \"" + book.getTitle() + "\"."); // \n prints a new line // \t prints a tab return false; } } /** * Returns the book that the member has, if possible. Returns true if * successful, or false if not. * * @return true if the operation is successful, or false if not */ public boolean returnBook() { if (book != null) { // the member has a book and // wants to return it. System.out.println( "The book titled \"" + book.getTitle() + "\" has been returned."); book = null; return true; } else { // The member doesn't have a book System.out.println("You don't have a book!"); return false; } } }