Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Driver file incomplete port java.util.ArrayList; import java.util.Collections; p

ID: 3725582 • Letter: D

Question



Driver file incomplete port java.util.ArrayList; import java.util.Collections;
public class Library { // Declare a List of LibraryBook ArrayList<LibraryBook> bookList; Library () { // TO DO: Instantiate bookList } /** TO DO: * adds the given book to the library * @param book */ public void addBook (LibraryBook book) {    } /** TO DO: * prints all books in the library */ public void printLibrary () { } /** TO DO: * locates a book in the library * @param book book being search in the library * @return book object if book is found * null otherwise */ public LibraryBook findBook (LibraryBook book) { int index = Collections.binarySearch(bookList, book);    /* @return book object if book is found * null otherwise */
} /** * sort books in the library by call number */ public void sortLibrary () { Collections.sort(bookList); } /** * performs processing for checking a book out of the library * @param patron person checking out book * @param dueDate date book is due to be returned * @param callNum call number of book */ public void checkout (String patron, String dueDate, String callNum) { LibraryBook searchItem = new CirculatingBook ("", "", "", callNum); LibraryBook book = findBook(searchItem); if (book == null) System.out.println ("Book " + callNum + " not found -- checkout impossible "); else book.checkout (patron, dueDate); } /** * processes checked-out book that is being returned * @param callNum call number of book being returned */ public void returned (String callNum) { LibraryBook searchItem = new CirculatingBook ("", "", "", callNum); LibraryBook book = findBook(searchItem); if (book == null) System.out.println ("Book " + callNum + " not found -- return impossible "); else book.returned (); } /** * main testing program * @param args not used */ public static void main (String args[]) {
Library lib = new Library (); // set up library lib.addBook(new ReferenceBook ("Henry M. Walker", "Problems for Computer Solution using BASIC", "0-87626-717-7", "QA76.73.B3W335", "Iowa Room")); lib.addBook(new ReferenceBook ("Samuel A. Rebelsky", "Experiments in Java", "0201612674", "64.2 R25ex", "Iowa Room")); lib.addBook(new CirculatingBook ("John David Stone", "Algorithms for functional programming", "in process", "forthcoming")); lib.addBook(new CirculatingBook ("Henry M. Walker", "Computer Science 2: Principles of Software Engineering, Data Types, and Algorithms", "0-673-39829-3", "QA76.758.W35"));
lib.addBook(new CirculatingBook ("Henry M. Walker", "Problems for Computer Solution using FORTRAN", "0-87626-654-5", "QA43.W34")); lib.addBook(new CirculatingBook ("Henry M. Walker", "Introduction to Computing and Computer Science with Pascal", "0-316-91841-5", "QA76.6.W3275")); lib.addBook(new CirculatingBook ("Samuel A. Rebelsky and Philip Barker", "ED-MEDIA 2002 : World Conference on Educational Multimedia, Hypermedia & Telecommunications", "14. 1-880094-45-2", "64.2 25e")); lib.addBook(new CirculatingBook ("Henry M. Walker", "Pascal: Problem Solving and Structured Program Design", "0-316-91848-2", "QA76.73.P2W35")); lib.addBook(new CirculatingBook ("Henry M. Walker", "The Limits of Computing", "0-7637-2552-8", "QA76.W185")); lib.addBook(new CirculatingBook ("Henry M. Walker", "The Tao of Computing", "0-86720-206-8", "QA76.W1855")); // sort books by call number lib.sortLibrary(); // print library lib.printLibrary(); // some users check out and return books lib.checkout("Donald Duck", "March 1, 2012", "QA43.W34"); lib.checkout("Donald Duck", "March 12, 2012", "QA76.6.W3275"); lib.checkout("Donald Duck", "March 6, 2012", "64.2 R25ex"); lib.checkout("Minnie Mouse", "April 1, 2012", "64.2 25e"); lib.checkout("Goofy", "February 28, 2012", "12345"); // should fail
lib.returned("QA76.6.W3275"); lib.returned("64.2 R25ex"); lib.checkout("Goofy", "March 28, 2012", "QA76.6.W3275"); // print final status of library lib.printLibrary(); } } port java.util.ArrayList; import java.util.Collections;
public class Library { // Declare a List of LibraryBook ArrayList<LibraryBook> bookList; Library () { // TO DO: Instantiate bookList } /** TO DO: * adds the given book to the library * @param book */ public void addBook (LibraryBook book) {    } /** TO DO: * prints all books in the library */ public void printLibrary () { } /** TO DO: * locates a book in the library * @param book book being search in the library * @return book object if book is found * null otherwise */ public LibraryBook findBook (LibraryBook book) { int index = Collections.binarySearch(bookList, book);    /* @return book object if book is found * null otherwise */
} /** * sort books in the library by call number */ public void sortLibrary () { Collections.sort(bookList); } /** * performs processing for checking a book out of the library * @param patron person checking out book * @param dueDate date book is due to be returned * @param callNum call number of book */ public void checkout (String patron, String dueDate, String callNum) { LibraryBook searchItem = new CirculatingBook ("", "", "", callNum); LibraryBook book = findBook(searchItem); if (book == null) System.out.println ("Book " + callNum + " not found -- checkout impossible "); else book.checkout (patron, dueDate); } /** * processes checked-out book that is being returned * @param callNum call number of book being returned */ public void returned (String callNum) { LibraryBook searchItem = new CirculatingBook ("", "", "", callNum); LibraryBook book = findBook(searchItem); if (book == null) System.out.println ("Book " + callNum + " not found -- return impossible "); else book.returned (); } /** * main testing program * @param args not used */ public static void main (String args[]) {
Library lib = new Library (); // set up library lib.addBook(new ReferenceBook ("Henry M. Walker", "Problems for Computer Solution using BASIC", "0-87626-717-7", "QA76.73.B3W335", "Iowa Room")); lib.addBook(new ReferenceBook ("Samuel A. Rebelsky", "Experiments in Java", "0201612674", "64.2 R25ex", "Iowa Room")); lib.addBook(new CirculatingBook ("John David Stone", "Algorithms for functional programming", "in process", "forthcoming")); lib.addBook(new CirculatingBook ("Henry M. Walker", "Computer Science 2: Principles of Software Engineering, Data Types, and Algorithms", "0-673-39829-3", "QA76.758.W35"));
lib.addBook(new CirculatingBook ("Henry M. Walker", "Problems for Computer Solution using FORTRAN", "0-87626-654-5", "QA43.W34")); lib.addBook(new CirculatingBook ("Henry M. Walker", "Introduction to Computing and Computer Science with Pascal", "0-316-91841-5", "QA76.6.W3275")); lib.addBook(new CirculatingBook ("Samuel A. Rebelsky and Philip Barker", "ED-MEDIA 2002 : World Conference on Educational Multimedia, Hypermedia & Telecommunications", "14. 1-880094-45-2", "64.2 25e")); lib.addBook(new CirculatingBook ("Henry M. Walker", "Pascal: Problem Solving and Structured Program Design", "0-316-91848-2", "QA76.73.P2W35")); lib.addBook(new CirculatingBook ("Henry M. Walker", "The Limits of Computing", "0-7637-2552-8", "QA76.W185")); lib.addBook(new CirculatingBook ("Henry M. Walker", "The Tao of Computing", "0-86720-206-8", "QA76.W1855")); // sort books by call number lib.sortLibrary(); // print library lib.printLibrary(); // some users check out and return books lib.checkout("Donald Duck", "March 1, 2012", "QA43.W34"); lib.checkout("Donald Duck", "March 12, 2012", "QA76.6.W3275"); lib.checkout("Donald Duck", "March 6, 2012", "64.2 R25ex"); lib.checkout("Minnie Mouse", "April 1, 2012", "64.2 25e"); lib.checkout("Goofy", "February 28, 2012", "12345"); // should fail
lib.returned("QA76.6.W3275"); lib.returned("64.2 R25ex"); lib.checkout("Goofy", "March 28, 2012", "QA76.6.W3275"); // print final status of library lib.printLibrary(); } }
class and its subclasses A more detailed description of these classes follows Class Book The Book class models information common to all books. Any book has: Fields: o an author o a title o an ISBN or International Standard Book Number that provides a unique number used by publishers and book o a null constructor o a constructor using 3 parameters for an author, title, and ISBN number o getters and setters o toString should provide a string of the field data in a format suitable for printing Within a Book class and its subclasses, these fields might be used directly, but processing by other classes and objects should be done via getters and setters- encapsulation! Class LibraryBook The LibraryBook class models information common for library books. In addition to author, title, and ISBN, library books have call numbers, and library books are stored on the shelves in order by call number. Further, many library books may be able to circulate. In addition to fields and methods of books, any library book has: Fields: o call number Constructors and methods: o a constructor using 4 parameters for an author, title, ISBN number, and call number o getters and setters o checkout handles processing for a patron to check out a o returned handles o circulationStatus indicates whether the book is on book. A due date also is recorded returned after having been checked out. the shelves, checked, or non-circulating in the reference processing for when a book is collection mpareTo allows comparison/ordering of library books, following the format Java's Comparable interface. o co

Explanation / Answer

package cheggindia;

import java.util.ArrayList;
import java.util.Collections;

class Book {

    protected String author;//Protected, So that the information can be used directlt in subclasses of Book
    protected String title;
    protected String isbn;

    public Book() {
    }//null/ default constructor

    public Book(String author, String title, String isbn) {//A parameterized constructor
        this.author = author;
        this.title = title;
        this.isbn = isbn;
    }

    //Override toString method to provide information suitable for printing
    @Override
    public String toString() {
        String str = "Book Author " + author + " "
                + "Book Title " + title + " "
                + "Book ISBN " + isbn + " ";
        return str;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getIsbn() {
        return isbn;
    }

    public void setIsbn(String isbn) {
        this.isbn = isbn;
    }

}
//Finished Class Book

abstract class LibraryBook extends Book implements Comparable<LibraryBook>{

    private String callNumber;

    public LibraryBook(String author, String title, String isbn,String callNumber) {
        super(author, title, isbn);
        this.callNumber = callNumber;
    }

    public String getCallNumber() {
        return callNumber;
    }

    public void setCallNumber(String callNumber) {
        this.callNumber = callNumber;
    }
  
    abstract void checkout(String patron, String dueDate);

    abstract void returned();
      
    abstract String circulationStatus(String callNumber);

    @Override
    public int compareTo(LibraryBook t) {
        return this.callNumber.compareTo(t.callNumber);
    }
    @Override
    public String toString(){
        return super.toString()+" "+
                "Call Number "+callNumber;
    }
}
class ReferenceBook extends LibraryBook{
    private String collection;

    public ReferenceBook(String author, String title, String isbn,String callNumber,String collection) {
        super(author, title, isbn,callNumber);
        this.collection = collection;
    }

    public String getCollection() {
        return collection;
    }

    public void setCollection(String collection) {
        this.collection = collection;
    }

    @Override
    void checkout(String patron, String dueDate) {
        System.out.println("Cannot Checkout a Reference Book");
    }

    @Override
    void returned() {
        System.out.println("Reference Book could not have been checked out -- Return impossible");
    }

    @Override
    String circulationStatus(String callNumber) {
        return "Non-circulating Reference book";
    }
  
    @Override
    public String toString(){
        return super.toString()+" "+
                "Collection "+collection;
    }
}
class CirculatingBook extends LibraryBook {
    private String currentHolder;
    private String dueDate;

    public CirculatingBook( String author, String title, String isbn, String callNumber) {
        super( author, title, isbn,callNumber);
        currentHolder=null;
        dueDate=null;
    }
  
    @Override
    void checkout(String patron, String dueDate) {
        this.currentHolder=patron;
        this.dueDate=dueDate;
    }

    @Override
    void returned() {
        currentHolder=null;
        dueDate=null;
    }

    @Override
    String circulationStatus(String callNumber) {
        //Return current holder's name if book has been issued
        return this.currentHolder==null?"Book available on Shelves":"Current Holder"+this.currentHolder;
    }

    public String getCurrentHolder() {
        return currentHolder;
    }

    public void setCurrentHolder(String currentHolder) {
        this.currentHolder = currentHolder;
    }

    public String getDueDate() {
        return dueDate;
    }

    public void setDueDate(String dueDate) {
        this.dueDate = dueDate;
    }
  
    @Override
    public String toString(){
        //Check if there is a current holder, if not then just print book information
        return this.currentHolder==null?super.toString():super.toString()+" "+
                "Current Holder "+currentHolder+" "+
                "Due Date "+dueDate;
    }
  
}
public class Library {
    // Declare a List of LibraryBook

    ArrayList<LibraryBook> bookList;

    Library() {
        // TO DO: Instantiate bookList
        bookList=new ArrayList();//create a new Book List which can store Library Books
    }

    /**
     * performs processing for checking a book out of the library
     *
     * @param patron person checking out book
     * @param dueDate date book is due to be returned
     * @param callNum call number of book
     */
    public void checkout(String patron, String dueDate, String callNum) {
        LibraryBook searchItem = new CirculatingBook("", "", "", callNum);
        LibraryBook book = findBook(searchItem);
        if (book == null) {
            System.out.println("Book " + callNum + " not found -- checkout impossible ");
        } else {
            book.checkout(patron, dueDate);
        }
    }

    /**
     * processes checked-out book that is being returned
     *
     * @param callNum call number of book being returned
     */
    public void returned(String callNum) {
        LibraryBook searchItem = new CirculatingBook("", "", "", callNum);
        LibraryBook book = findBook(searchItem);
        if (book == null) {
            System.out.println("Book " + callNum + " not found -- return impossible ");
        } else {
            book.returned();
        }
    }
    /**
     * TO DO: adds the given book to the library
     *
     * @param book
     */
    public void addBook(LibraryBook book) {
        bookList.add(book);//add the new book to the library list
    }

    /**
     * TO DO: prints all books in the library
     */
    public void printLibrary() {
        for(int i=0;i<bookList.size();i++){
            System.out.println(""+bookList.get(i));
        }
    }

    /**
     * TO DO: locates a book in the library
     *
     * @param book book being search in the library
     * @return book object if book is found null otherwise
     */
    public LibraryBook findBook(LibraryBook book) {
        int index = Collections.binarySearch(bookList, book);
        if(index>=0)//the book is found
            return bookList.get(index); //return the book object if book is found
        return null;//return null if book couldn't be found
    }

    /**
     * sort books in the library by call number
     */
    public void sortLibrary() {
        Collections.sort(bookList);
    }

    /**
     * main testing program
     *
     * @param args not used
     */
    public static void main(String args[]) {

        Library lib = new Library();
        // set up library
        lib.addBook(new ReferenceBook("Henry M. Walker",
                "Problems for Computer Solution using BASIC",
                "0-87626-717-7", "QA76.73.B3W335", "Iowa Room"));
        lib.addBook(new ReferenceBook("Samuel A. Rebelsky",
                "Experiments in Java",
                "0201612674", "64.2 R25ex", "Iowa Room"));
        lib.addBook(new CirculatingBook("John David Stone",
                "Algorithms for functional programming",
                "in process", "forthcoming"));
        lib.addBook(new CirculatingBook("Henry M. Walker",
                "Computer Science 2: Principles of Software Engineering, Data Types, and Algorithms",
                "0-673-39829-3", "QA76.758.W35"));
        lib.addBook(new CirculatingBook("Henry M. Walker",
                "Problems for Computer Solution using FORTRAN",
                "0-87626-654-5", "QA43.W34"));
        lib.addBook(new CirculatingBook("Henry M. Walker",
                "Introduction to Computing and Computer Science with Pascal",
                "0-316-91841-5", "QA76.6.W3275"));
        lib.addBook(new CirculatingBook("Samuel A. Rebelsky and Philip Barker",
                "ED-MEDIA 2002 : World Conference on Educational Multimedia, Hypermedia & Telecommunications",
                "14. 1-880094-45-2", "64.2 25e"));
        lib.addBook(new CirculatingBook("Henry M. Walker",
                "Pascal: Problem Solving and Structured Program Design",
                "0-316-91848-2", "QA76.73.P2W35"));
        lib.addBook(new CirculatingBook("Henry M. Walker",
                "The Limits of Computing",
                "0-7637-2552-8", "QA76.W185"));
        lib.addBook(new CirculatingBook("Henry M. Walker",
                "The Tao of Computing",
                "0-86720-206-8", "QA76.W1855"));

        // sort books by call number
        lib.sortLibrary();

        // print library
        lib.printLibrary();

        // some users check out and return books
        lib.checkout("Donald Duck", "March 1, 2012", "QA43.W34");
        lib.checkout("Donald Duck", "March 12, 2012", "QA76.6.W3275");
        lib.checkout("Donald Duck", "March 6, 2012", "64.2 R25ex");
        lib.checkout("Minnie Mouse", "April 1, 2012", "64.2 25e");
        lib.checkout("Goofy", "February 28, 2012", "12345"); // should fail

        lib.returned("QA76.6.W3275");
        lib.returned("64.2 R25ex");

        lib.checkout("Goofy", "March 28, 2012", "QA76.6.W3275");

        // print final status of library
        lib.printLibrary();
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote