Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python3 Library and SchoolLibrary class implementation MAKE SURE TO PASS THESE DOCTESTS CHECK_OUT = 'Checking out book failed' MEMBER_IN_SYSTEM = 'Member already in the Library

Python3 Library and SchoolLibrary class implementation image text in transcribed MAKE SURE TO PASS THESE DOCTESTS CHECK_OUT = 'Checking out book failed' MEMBER_IN_SYSTEM = 'Member already in the Library System' MEMBER_NOT_IN_SYSTEM = 'Member is not in the Library System'

class Library: """ >>> sd = Library('San Diego') >>> sd.add_book('Harry Potter') >>> sd.get_num_books() 1 >>> sd.catalog[0] 'Harry Potter' >>> sd.check_out('Harry Potter') >>> sd.get_num_books() 0 >>> sd.check_out('Tarzan') Checking out book failed >>> sd.get_location() 'San Diego'

>>> la = Library('Los Angeles') >>> la.get_location() 'Los Angeles' >>> la.add_member('Harsh') >>> la.add_member('Harsh') Member already in the Library System >>> Library.members[0] 'Harsh' >>> sd.remove_member('Harsh') >>> sd.remove_member('Harsh') Member is not in the Library System >>> len(Library.members) 0 >>> la.add_member('Brian')

>>> giesel = SchoolLibrary('San Diego', 'UCSD') >>> giesel.add_member('Harsh') >>> giesel.get_school_name() 'UCSD' >>> SchoolLibrary.members ['Brian', 'Harsh'] >>> Library.members ['Brian', 'Harsh'] >>> giesel.members ['Brian', 'Harsh'] """

#keeps track of members across all libraries (a class attribute) members = [] # Create a constructor which will intialize a library's location given its parameter and an empty # list object called catalog which will store book names ### YOUR CODE GOES HERE ###

def add_book(_____, book): ______.catalog.append(book) def check_out(______, book): if book in ______.catalog: _______.catalog.remove(book) else: print(CHECK_OUT) def get_location(_______): ''' Returns the location of a Library''' return _________ def get_num_books(_______): ''' Returns the total number of books in a Library (in its catalog) ''' return ___________ def add_member(self, member): ''' Check if a member is already in our member system (our class attribute), if it is print the appropriate error message provided, if it is not then add the member ''' ### YOUR CODE GOES HERE ###

def remove_member(self, member): ''' Check if a member is already in our member system (our class attribute), if it is not then print the appropriate error message provided, if it is then remove that member ''' ### YOUR CODE GOES HERE ###

# What should be in the blank, so that our SchoolLibrary class inherits Library? # Uncomment the following line and finish the task

# class SchoolLibrary(______): # Craete a SchoolLibrary constructor using the Library class constructor and # initialize its location and its school_name variable ### YOUR CODE GOES HERE ### def get_school_name(_____): '''Returns the name of the school''' return _________

For doctests please refer to the starter code Do not modify the starter code except in the allowed places: *YOUR CODE GOES HERE* and " For the declaration of class SchoolLibrary, please uncomment the following line before you start: # class Schoo!Library ( In this question you will be asked to create two classes: Library and SchoolLibrary Library class has the following attributes and methods e member - a CLASS ATTRIBUTE which keeps track of members in all libraries (class attribute is an attribute shared by all the instances of that class) - constructor to create an instance of Library object constructor o takes location as its argument o creates location as an object attribute o catalog (lists of books) which is initially empty. Another object attribute - a string of where the Library is located -the list of books this Library contains - adds a given book (for this question just the name of book) to the Library catalog, as a string -checks out a book from the Library catalog(if check out failed, a corresponding error message should be printed) -returns the location of the Library . add_book() . check_out() . get_location) .get_num_books() returns the number of books in the Library . add_member adds a person to the Library membership list remove member() -removes a person from the Library membership list SchoolLibrary class is a child (subclass) class of Library and has the following attributes and methods (besides those already defined in Library) constructor to create an instance of SchoolLibrary object. (Note: Since SchoolLibrary is inherited from Library, what extra line should you add?) constructor . get_school_name) - returns the name of the school which is part of the SchoolLibrary object only

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

Lab Manual For Database Development

Authors: Rachelle Reese

1st Custom Edition

1256741736, 978-1256741732

More Books

Students also viewed these Databases questions

Question

2. What do you believe is at the root of the problem?

Answered: 1 week ago