Menu

Writing Library Simulator Involving Multiple Classes Write Libraryitem Patron Library Clas Q43817912

You will be writing a Library simulator involving multipleclasses. You will write the LibraryItem, Patron, and Libraryclasses and the three classes that inherit from LibraryItem (Book,Album and Movie). All data members of each class should be markedas private and the classes should have any get or set methods thatwill be needed to access them.

**USE PYTHON 3 ONLY!!!

Here are descriptions of the three classes:

LibraryItem:

  • id_code – a unique identifier for a LibraryItem – you canassume uniqueness, you don’t have to enforce it
  • title – cannot be assumed to be unique
  • location – a LibraryItem can be “ON_SHELF”, “ON_HOLD_SHELF”, or”CHECKED_OUT”
  • checked_out_by – refers to the Patron who has it checked out(if any)
  • requested_by – refers to the Patron who has requested it (ifany); a LibraryItem can only be requested by one Patron at atime
  • date_checked_out – when a LibraryItem is checked out, this willbe set to the current_date of the Library
  • init method – takes an id_code, and title; checked_out_by andrequested_by should be initialized to None; a new LibraryItem’slocation should be on the shelf
  • get and set methods

Book/Album/Movie:

  • These three classes all inherit from LibraryItem.
  • All three will need a method called get_check_out_length thatreturns the number of days that type of library item may be checkedout for. For a Book it’s 21 days, for an Album it’s 14 days, andfor a Movie it’s 7 days.
  • All three will have an additional field. For Book, it’s astring field called author. For Album, it’s a string field calledartist. For Movie, it’s a string field called director. There willalso need to be get methods to return the values of thesefields.

Patron:

  • id_num – a unique identifier for a Patron – you can assumeuniqueness, you don’t have to enforce it
  • name – cannot be assumed to be unique
  • checked_out_items – a list of LibraryItems that a Patroncurrently has checked out
  • fine_amount – how much the Patron owes the Library in latefines (measured in dollars); this is allowed to go negative
  • init method – takes an idNum and name
  • get and set methods
  • add_library_item – adds the specified LibraryItem tochecked_out_items
  • remove_library_item – removes the specified LibraryItem fromchecked_out_items
  • amend_fine – a positive argument increases the fine_amount, anegative one decreases it; this is allowed to go negative

Library:

  • holdings – a list of the LibraryItems in the Library
  • members – a list of the Patrons in the Library
  • current_date – stores the current date represented as aninteger number of “days” since the Library object was created
  • a constructor that initializes the current_date to zero
  • add_library_item – adds the parameter to holdings
  • add_patron – adds the parameter to members
  • get_library_item – returns the LibraryItem corresponding to theID parameter, or None if no such LibraryItem is in theholdings
  • get_patron – returns the Patron corresponding to the IDparameter, or None if no such Patron is a member
  • In check_out_library_item, return_library_item andrequest_library_item, check the listed conditions in the ordergiven – for example, if check_out_library_item is called with aninvalid LibraryItem ID and an invalid Patron ID, it should justreturn “item not found”.
  • check_out_library_item
    • if the specified LibraryItem is not in the Library’s holdings,return “item not found”
    • if the specified Patron is not in the Library’s members, return”patron not found”
    • if the specified LibraryItem is already checked out, return”item already checked out”
    • if the specified LibraryItem is on hold by another Patron,return “item on hold by other patron”
    • otherwise update the LibraryItem’s checkedOutBy, dateCheckedOutand Location; if the LibraryItem was on hold for this Patron,update requestedBy; update the Patron’s checkedOutItems; return”check out successful”
  • return_library_item
    • if the specified LibraryItem is not in the Library’s holdings,return “item not found”
    • if the LibraryItem is not checked out, return “item already inlibrary”
    • update the Patron’s checkedOutItems; update the LibraryItem’slocation depending on whether another Patron has requested it (ifso, it should go on the hold shelf); update the LibraryItem’scheckedOutBy; return “return successful”
  • request_library_item
    • if the specified LibraryItem is not in the Library’s holdings,return “item not found”
    • if the specified Patron is not in the Library’s members, return”patron not found”
    • if the specified LibraryItem is already requested, return “itemalready on hold”
    • update the LibraryItem’s requestedBy; if the LibraryItem is onthe shelf, update its location to on hold; return “requestsuccessful”
  • pay_fine
    • takes as a parameter the amount that is being paid (not thenegative of that amount)
    • if the specified Patron is not in the Library’s members, return”patron not found”
    • use amendFine to update the Patron’s fine; return “paymentsuccessful”
    • increment_current_date
    • increment current date; increase each Patron’s fines by 10cents for each overdue LibraryItem they have checked out (usingamendFine)

Note – a LibraryItem can be on request without its locationbeing the hold shelf (if another Patron has it checked out);

One limited example of how your classes might be used is:

b1 = Book(“123”, “War and Peace”, “Tolstoy”) b2 = Book(“234”, “Moby Dick”, “Melville”) b3 = Book(“345”, “Phantom Tollbooth”, “Juster”) p1 = Patron(“abc”, “Felicity”) p2 = Patron(“bcd”, “Waldo”) lib = Library() lib.add_library_item(b1) lib.add_library_item(b2) lib.add_library_item(b3) lib.add_patron(p1) lib.add_patron(p2) lib.check_out_library_item(“bcd”, “234”) for i in range(7): lib.increment_current_date() lib.check_out_library_item(“bcd”, “123”) lib.check_out_library_item(“abc”, “345”) for i in range(24): lib.increment_current_date() lib.pay_fine(“bcd”, 0.4) p1Fine = p1.get_fine_amount() p2Fine = p2.get_fine_amount()

This example obviously doesn’t include all of the functionsdescribed above. You are responsible for testing all of therequired functions to make sure they operate as specified.

Your file must be named: Library.py

Just to think about: Since there are three possible locationsfor a LibraryItem, there are six hypothetical changes in location.Are all six possible according to these specifications?

Expert Answer


Answer to You will be writing a Library simulator involving multiple classes. You will write the LibraryItem, Patron, and Library …

OR