/* * File: LibraryRecordTest.java * ---------------------------- * Simple test of the LibraryRecord class. */ import acm.program.*; public class LibraryRecordTest extends ConsoleProgram { public void run() { LibraryRecord book1 = new LibraryRecord("The Art and Science of C", "Eric Roberts", "QA76.73.C15", "Addison-Wesley", 1995); LibraryRecord book2 = new LibraryRecord("Euclid's Elements", "Robert of Chester", "QA31.B87", "none", 1250, false); println(book1); println(book2); } /** * The LibraryRecord class keeps track of the following pieces of data * about a library book: title, author, catalog number, publisher, year * of publication, and a flag indicating whether the book is circulating. */ public class LibraryRecord { /** * Creates a new LibraryRecord object with the specified information. * * @param title The title of the book * @param author The author's name * @param number The catalog number as a string * @param publisher The publisher's name * @param year The year of publication * @param circulates A flag indicating whether the book circulates */ public LibraryRecord(String title, String author, String number, String publisher, int year, boolean circulates) { bookTitle = title; authorName = author; catalogNumber = number; publisherName = publisher; publicationYear = year; circulatingFlag = circulates; } /** * Creates a new LibraryRecord object with the specified information, * setting the record to be circulating by default. * * @param title The title of the book * @param author The author's name * @param number The catalog number as a string * @param publisher The publisher's name * @param year The year of publication */ public LibraryRecord(String title, String author, String number, String publisher, int year) { this(title, author, number, publisher, year, true); } /** * Gets the title of this book. * @return The title of the book */ public String getTitle() { return bookTitle; } /** * Gets the name of the author. * @return The name of the author */ public String getAuthor() { return authorName; } /** * Gets the Library of Congress catalog number of this book. * @return The catalog number of the book as a string */ public String getCatalogNumber() { return catalogNumber; } /** * Gets the name of the publisher. * @return The name of the publisher */ public String getPublisherName() { return publisherName; } /** * Gets the year of publication. * @return year of publication */ public int getPublicationYear() { return publicationYear; } /** * Sets whether the book is circulating. * @param circulates A boolean flag indicating whether it circulates */ public void setCirculating(boolean circulates) { circulatingFlag = circulates; } /** * Returns whether the book is circulating. * @return Whether the book is circulating */ public boolean isCirculating() { return circulatingFlag; } /** * Creates a string identifying this book. * @return The string used to identify this book */ public String toString() { String str = " " + authorName + "."; str += " " + bookTitle + "."; str += " " + publisherName + ", " + publicationYear + "."; str += " [" + catalogNumber; if (!circulatingFlag) str += ", noncirculating"; str += "]"; return str; } /* Private instance variables */ private String bookTitle; /* The book title */ private String authorName; /* The author's name */ private String catalogNumber; /* The catalog number */ private String publisherName; /* The publisher name */ private int publicationYear; /* The year of publication */ private boolean circulatingFlag; /* Does this book circulate */ } /* class LibraryRecord */ } /* LibraryRecordTest */