Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

project-3 You will be writing a Library simulator involving multiple classes. You will write the Libraryltem. Patron and Library classes, and the three classes that

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
project-3 You will be writing a Library simulator involving multiple classes. You will write the Libraryltem. Patron and Library classes, and the three classes that inherit from Libraryltem (Book. Album and Movie). All data members of each class should be marked as private (a leading underscore in the name). Since theyre private, if you need to access them from outside the class, you should do so via get or set methods. Any get or set methods should be named per the usual convention ("get_" or "set "followed by the name of the data member). Here are descriptions of the three classes: Libraryitem: A Libraryltem object represents a library item that a patron can check out from a library. It has six data members: - library_item_id - a unique identifier for a Libraryitem - you can assume uniqueness, you don't have to enforce it - title - cannot be assumed to be unique - location - a Libraryltem 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 (if any); a Libraryltem can only be requested by one Patron at a time - date_checked_out - when a Libraryltem is checked out, this will be set to the current_date of the Library The Libraryltem methods are: - init method - takes a library item ID and tille as parameters; checked_out_by and requested_by should be initialized to None; a new Libraryitem's location shouid be on the shelf - get location returns the Library ltem's location - other get and set methods as needed Book/Album/Movie: - These three classes all inherit from Libraryltem - All three will need an additional data member. For Book, it's a string called author. For Album, it's a string called artist. For Movie, it's a string called director - Each of the new data members will need a get method to return its value - All three will need a method called get_check_out_length that returns the number of days that type of library item may be checked out for. For a Book it's 21 days, for an Album it's 14 days, and for a Movie it's 7 days Patron: A Patron object represents a patron of a library. It has four data members: - patron_id-a unique identifier for a Patron - you can assume uniqueness, you don't have to enforce it - name - cannot be assumed to be unique - checked_out_items - a collection of Libraryltems that a Patron currently has checked out - fine_amount - how much the Patron owes the Library in late fines (measured in dotlars). this is allowed to go negative The Patron methods are: - init method - takes a patron ID and name as parameters - get_fine_amount - returns the fine_amount - other get and set methods as needed - add library_item - adds the specified Libraryltem to checked_out_items - remove_fibrary_item - removes the specified Libraryltem from checked_out_items - amend_fine - a positive argument increases the fine_ amount, a negative one decreases it; this is allowed to go negative Library: A Library object represents a library that contains variaous library items, and is used by various patrons. It has three data members: - holdings - a collection of the Libraryltems that belong to the Library - members - a collection of the Patrons who are members of the Library - current date - stores the current date represented as an integer number of "days" since the Library object was created The Library methods are: - an init method that initializes the holdings and members as empty collections and initializes the current_date to zero - add library_item-takes a Libraryltem object as a parameter and adds it to the hoidings - add patron - takes a Patron object as a parameter and adds it to the members: - lookup library_item_from_id - returns the Libraryltem object corresponding to the ID parameter, or None if no such Libraryltem is in the holdings - lookup_patron_from_id-retums the Patron object corresponding to the ID parameter, or None if no such Patron is a member - check_out library_item takes as parameters a patron 1D and a library item ID, in that order if the specified Patron is not in the Library's members, return "patron not found" if the specified Libraryltem is not in the Library's holdings, return "item not found" if the specified Libraryltem is already checked out, return "item already checked out o n if the specified Libraryltem is on hold by another Patron, return "item on hold by other patron" otherwise update the Libraryltem's checked_out_by, date_checked out and location if the Libraryltem was on hold for this Patron, update requested by update the Patron's checked out items return "check out successful" - return library item takes as its parameter a library item ID if the specified Libraryltem is not in the Library's holdings, return "item not found" if the Libraryltem is not checked out, return "item already in library" update the Patron's checked out items update the Libraryltem's location depending on whether another Patron has requested it (if so, it should go on the hold shelf) update the Libraryltem's checked_out_by return "return successful" - request_library_item - takes as parameters a patron ID and a library item ID, in that order if the specified Patron is not in the Library/s members, return "patron not found" if the specfied Libraryltem is not in the Library's holdings, return "item not found" - if the specified Libraryltem is already requested, return "item already on hold" update the Libraryltem's requested by if the Libraryltem is on the shelf, update its location to on hold return "request succestul" - pay_fine takes as parameters a Patron ID and the amount (in dollars) being paid (in that order) if the specified Patron is not in the Library's members, return "patron not found" o Use amend fine to update the Patron's fine; return "payment successful" - increment_current_date takes no parameters increment current date increase each Patron's fines by 10 cents for each overdue Libraryltem they have checked out (by calling amend fine) Note - a Libraryltem can be on request without its location being the hold shelf (if another Patron has it checked out); One limited example of how your classes might be used is: b1= Book(" 345n, "Phantom Tollbooth", "Juster") a1 = Album("456". . .. And His Orchestra", "The Fastbacks") m1= Movie("567", "Laputa", "Miyazaki") print(b1.get_author()) print(a1.get_artist()) print(m1.get_director()) p1 = Patron("abc", "Felicity") p2 = Patron("bcd", "Waldo") lib = Library() lib.add_library_item(b1) lib.add_library_item(a1) lib.add_patron(p1) lib.add_patron(p2) lib.check_out_library_item("bcd", "456") for in range(7): lib.increment_current_date() \#7 days pass lib.check_out_library_item("abc", "567") loc = a1.get_location() lib.request_library_item("abc", "456") for in range(57): lib.increment_current_date() \# 57 days pass p2_fine = p2.get_fine_amount() lib.pay_fine("bcd", p2_fine) lib.return_library_item("456") You are responsible for testing all of the required functions to make sure they operate as specified. Your file must be named: Library.py Just to think about: Since there are three possible locations for a Libraryltem, there are six hypothetical changes in location. Are all six possible according to these specifications

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions

Question

A base case is necessary for all recursive algorithms. True False

Answered: 1 week ago