JMU logo

CS 149: Programming Fundamentals 
James Madison University, Fall 2016 Semester 

PA6: Dukes Library (Classes and Objects)

Part A (30 pts): Due Monday, Dec 5 at 11:59 PM

Submit only your JUnit tests (BookTest.javaLibraryTest.java, and PatronTest.java) via Web-CAT.

Late work will not be accepted. If you do not complete
Part A by Monday, Dec 5 at 11:59 PM, you will receive a zero for Part A.

Part B (70 pts): Due Friday, Dec 9 at 11:59 PM

Submit all six files (Book.java and BookTest.javaLibrary.java 
and LibraryTest.javaPatron.javaand PatronTest.java) via Web-CAT.

  • -25% on Saturday, Dec 10 by 11:59 PM
  • -50% on Sunday, Dec 11 by 11:59 PM
  • Not accepted afterwards

You may (and should) revise your test cases in your final submission.

 

Objectives

Honor Code

This assignment must be completed individually. Your submission must conform to the JMU Honor Code. Authorized help is limited to general discussion on Piazza, the lab assistants assigned to CS 139/149, and the instructor. Copying work from another student or the Internet is an honor code violation and will be grounds for a reduced or failing grade in the course.

Background

This assignment is inspired by the Little Free Library organization which has managed to charter small "libraries" like the one shown above all across the world. Each "library" encourages patrons to take a book or leave a book to promote accessibility of books and reading in general. They are community spaces, many with benches or seats nearby and all are maintained by volunteers. There are eight in Harrisonburg. The one at Thomas Harrison Middle School was built by the JMU Art Department. The one shown above is the Elizabeth Street Little Free Library, and the data file you will be using in the assignment is based on the books available at this writing in the Elizabeth Street box.

Requirements

In this assignment, imagine that the Little Free Library organization has contracted with the JMU Computer Science department to track how much money they could earn if they were a commercial organization that charged late fees for overdue books. This information will then be used for local LFL librarians to apply for funding from other non-profit foundations or the government. Each book and patron will be modeled by classes with relevant data and methods as outlined in the UML diagram and descriptions shown below. The Library class will then have arrays of books and patrons along with methods that allow for books to be checked in, checked out, and found in addition to determining fines. Your program will be based on the following files:

  • DateUtils.java - This utility class is provided for you. Do not submit to Web-CAT.
  • Driver.java - This example class is provided for you. Do not submit to Web-CAT.
  • lflbooks.txt - Example books; based on Elizabeth St in Harrisonburg.
  • patrons.txt - Example patrons; feel free to add yourself to this file!

You don't actually need the Driver to complete the assignment; it is simply provided to show how your classes might be used in a larger application. The following UML diagram illustrates the relationship of the classes to one another.

Book.java

  1. The Book constructor will be used to initialize all attributes of the Book object. The initial status of the book should be AVAILABLE, and the patron and due date should be null.

  2. Like the constructor, the checkin method should set the book's status to AVAILABLE and assign null to both patron and due date.

  3. The checkout method should make the book UNAVAILABLE and save the given patron and due date in the object.

  4. The equals method checks whether two books have the same isbn. If the given object is a Book, compare this.isbn with the other book's isbn. If the given object is a String, compare this.isbn with the string.

  5. In the UML diagram, getX is actually eight methods: one accessor method for each of the eight attributes. These should be easy to implement (Eclipse will generate them automatically). Note that the class should have no "setX" methods.

  6. The toString method should return a String representation of the book. If a book is initialized with the following parameters ("aaa", "bbb", "1234BBBBBBBBB", 2013, 10), it should return a String exactly as follows: "Title: aaa, Author: bbb, ISBN: 1234BBBBBBBBB, Year: 2013, Pages: 10."

Patron.java

  1. The Patron constructor will be used to initialize all attributes of the Patron object.

  2. The adjustBalance will update the current balance of the patron. For example if the current balance of a Patron is 2.0 and the amount is 4.5, this method should assign 6.50 to this.balance and return 6.50.

  3. The equals method checks whether two patrons have the same id number. If the given object is a Patron, compare this.idNumber with the other patron's idNumber. If the given object is an Integer, compare this.idNumber with the Integer.

  4. The toString method should return a String representation of the Patron. If a patron is initialized with the following parameters ("bob", "eee", 2, 5.5), it should return a String exactly as follows: "Name: bob, Email: eee, ID: 2, Balance: $5.50."

Library.java

  1. The Library constructor will initialize an array of Book and Patron objects using the book and patron array parameters.

  2. The checkin method will check in a book upon return. If the returned book belongs in the Library, and it is currently checked out, this method should update the status of the book, reset its patron and due date, determine the fine for this book (if any), and update the patron's balance. The return value indicates success or failure. For example, if the book is not in the library, checkin should return false.

  3. The checkout method will let a patron checkout a book that is available in the Library. If the book belongs to the library and is available, this method will update it's status and patron, and set the due date to ten days from today's date. The return value indicates success or failure. For example, if the book is not in the library, checkout should return false.

  4. The determineFine method will compute the fine currently due for a book that is checked out. For this method, the fine rate is $0.50 per day for each day after the due date.

  5. The searchBooks method searches for books, depending on the key and type, and returns an array of the books found. If no books are found, the resulting array will have a length of zero.

    • When type is TITLE_SEARCH, key will be a string containing the title to search. The method should return all books with that title.
    • When type is AUTHOR_SEARCH, key will be a String containing the author's name. The method should return all books for that author.
    • When type is PATRON_SEARCH, key will either be a Patron object or an Integer with the Patron's id. The method should return all books checked out to that patron.
    • When type is OVERDUE_SEARCH, key will be a Date object. The method should return all books that will be overdue on that date (if not checked in before then).

Hints and Tips


Contact chaoaj[at]jmu.edu for more information about this page or Twitter: @chaoaj