Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python please this is the input file there is no 'Book' description Define a class named MyLibrary which represents a simple library system. The simple

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedpython please

this is the input file
image text in transcribed
there is no 'Book' description
Define a class named MyLibrary which represents a simple library system. The simple library system should allow people to borrow, return and search for books in the collection. It also provides the functionalities such as displaying the list of available books and a list of on-loan books, etc. The MyLibrary class contains: A private data field named name that defines the name of a library. A private data field named _books_list that defines a list of the Book objects in the library. A constructor/initializer that takes a name and a filename as parameters (default of empty string). If the filename is not an empty string, the method should load all the books from a text file into the books list of the library system. Download the sample text files from here. o If the file does not exist, an error message is displayed as in the example below. o After loading all the books into the books list, the method should print the number of books loaded as in the example below. The show_all_books (self) method which prints out all the books in the collection as shown in the example below. Note: You can assume that the Book class is given. Keep a copy of your solution to this task because you will be extending it step by step in subsequent tasks. For example: Test Result = library MyLibrary( 'MyLibrary', 'simple_books.txt') 5 books loaded. print() library.show_all_books () The Lord Of The Rings, QS12.03.001 (Available) The Hitchhiker's Guide To The Galaxy, QK12.04.002 (Available) The Dune Chronicles, QS12.02.003 (Available) A Song of Ice And Fire Series, QA12.04.004 (Available) The Foundation Trilogy, QS12.01.005 (Available) ERROR: The file 'input_file.txt' does not exist. library MyLibrary( 'MyLibrary','input_file.txt') library.show_all_books () Starting with your solution to the previous task, extend the MyLibrary class by implementing the following methods: The find_available_book(self, code) method which takes a book code as a parameter and searches through the collection of books based on a given code. If the book is found and it is available, the method should return the Book object, and None otherwise. The borrow_book(self, code, borrower_name) method which takes a book code and a name of the borrower as parameters. The method should search for the book in the books list. If the book is available, the method should issue the book to the borrower by calling the borrow_book () method on the Book and print a message as in the example below. If the book is NOT available, the method should print "ERROR: could not issue the book: 'XXX" where XXX indicates the book code. Note: You can assume that the Book class is given. Keep a copy of your solution to this task because you will be extending it step by step in subsequent tasks. For example: Test Result 5 books loaded. The Dune Chronicles, QS12.02.003 (Available) None library = MyLibrary( 'MyLibrary', 'simple_books.txt') print(library.find_available_book( 'QS12.02.003')) print(library.find_available_book( '003')) library MyLibrary( 'MyLibrary','simple_books.txt') library.borrow_book ('QS12.02.003', 'Michael') library.borrow_book ( '003', 'Michael') 5 books loaded. 'The Dune Chronicles' is issued to Michael successfully. ERROR: could not issue the book: '003'. Starting with your solution to the previous task, extend the MyLibrary class by implementing the following methods: The find_on_loan_book(self, code) method which takes a book code as a parameter and and searches through the collection of books based on the parameter code. If the book is found and it is on loan, the method should return the Book object, and None otherwise. The return_book(self, code) method which takes a book code as a parameter and searches through the collection of books based on the parameter code. If the book is on loan, the method should return the book and print a message as in the example below. If the book is not "on loan" or cannot be found, the method should print "ERROR: could not return the book: XXX" where XXX indicates the book code. Note: You can assume that the Book class is given. Keep a copy of your solution to this task because you will be extending it step by step in subsequent tasks. For example: Test Result library = MyLibrary( 'MyLibrary', 'simple_books.txt') 5 books loaded. library.borrow_book( 'QS12.02.003', 'Michael') "The Dune Chronicles' is issued to Michael successfully. library.return_book ('QS12.02.003') "QS12.02.003' is returned successfully. print(library.find_available_book( 'QS12.02.003')) The Dune Chronicles, QS12.02.003 (Available) library - MyLibrary( 'MyLibrary', 'simple_books.txt') 5 books loaded. library.return_book ('QS12.02.003') ERROR: could not return the book: 'QS12.02.003'. library.return_book ('003') ERROR: could not return the book: '003'. Starting with your solution to the previous task, extend the MyLibrary class by implementing the following methods: The show_available_books (self) method which prints all the available books in the library system. The show_on_loan_books (self) method which prints all the on loan books in the library system. Note: You can assume that the Book class is given. For example: Test Result library = MyLibrary( 'MyLibrary', 'simple_books.txt') 5 books loaded. library.borrow_book ('QS12.02.003', 'Michael') 'The Dune Chronicles' is issued to Michael successfully. library.borrow_book ('QK12.04.002' 'Michael') 'The Hitchhiker's Guide To The Galaxy' is issued to Michael successfully. print("Available books:") Available books: library.show_available_books () The Lord Of The Rings, QS12.03.001 (Available) print("On loan books:") A Song of Ice And Fire Series, QA12.04.004 (Available) library.show_on_loan_books () The Foundation Trilogy, QS12.01.005 (Available) On loan books: The Hitchhiker's Guide To The Galaxy, QK12.04.002 (On Loan) The Dune Chronicles, QS12.02.003 (On Loan) QS12.03.001,The Lord Of The Rings QK12.04.002,The Hitchhiker's Guide To The Galaxy QS12.02.003,The Dune Chronicles QA12.04.004, A Song Of Ice And Fire Series QS12.01.005,The Foundation Trilogy

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

More Books

Students also viewed these Databases questions

Question

denigration of emotional outbursts; being reserved;

Answered: 1 week ago