Description
Unformatted Attachment Preview
Purchase answer to see full attachment
Explanation & Answer
Hey check it out. Everything is attached
Develop a Library class that can manage the books and patrons from Exercise 1. This class
should include methods for adding, removing, and finding books and patrons: addBook,
addPatron, removeBook, removePatron, findBook, and findPatron, respectively for
each. There should also be methods for borrowing and returning a book: borrowBook and
returnBook, respectively. If you have yet to add a data member to keep track of the list of
books a patron has borrowed, now would be a good time to do so.
Now, write a driver program to test all of these methods.
Here is an example driver program:
from library import Library from book import Book
from patron import Patron
def main():
book1 = Book("Of Mice and Men", "Steinbeck")
book2 = Book("The Great Gatsby", "Fitzgerald")
book3 = Book("1984", "Orwell")
book4 = Book("One Flew Over the Cuckoo's Nest", "Kesey")
libraryBooks = []
libraryBooks.append(book1)
libraryBooks.append(book2)
libraryBooks.append(book3)
libraryBooks.append(book4)
patron1 = Patron("Ivan") patron2 = Patron("Jimmy") patron3 = Patron("Bob")
myLibrary = Library(libraryBooks)
myLibrary.addPatron(patron1)
myLibrary.addPatron(patron2)
myLibrary.addPatron(patron3)
myLibrary.borrowBook(book1, patron2)
myLibrary.borrowBook(book1, patron3)
print(str(myLibrary))
myLibrary.returnBook(book1)
print(str(myLibrary))
if __name__ == '__main__': main()
and, the associated output:
Books:
Of Mice and Men, Steinbeck in care of: Jimmy has 1 books. Waiting:
1. Bob has 0 books.
The Great Gatsby, Fitzgerald and has not been borrowed. Waiting:
1984, Orwell and has not been borrowed.
Waiting:
One Flew Over the Cuckoo's Nest, Kesey and has not been borrowed. Waiting:
Patrons:
Ivan has 0 books.
Jimmy has 1 books.
Bob has 0 books.
Returned: Of Mice and Men, Steinbeck in care of: Jimmy has 0 books. Waiting:
1....