Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON Q2: You are required to design a system for a library to keep track of the available books in the library and their customers.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

PYTHON

Q2: You are required to design a system for a library to keep track of the available books in the library and their customers. The description of the classes as follows: (NOTE: All attributes and methods are public) 1. A class Person which has the following attributes and methods: a. ID - a unique integer b. name - string c. A constructor that initializes the person's name and set its ID. d. An _str_method that returns the ID and name as string. 2. A class Customer which is also a Person, in addition to the Person attributes it has the following attributes: a. MEMBERSHIPS - a tuple class attribute with the following values "PLATENIUM, SILVER, or GOLD" b. membership - a string that can be only one of the MEMBERSHIPS element c. A constructor that initializes the customer membership and ID and name. d. An _str_ method that make a string of the ID and name (by calling the class Person__str__ and membership and then returns it. 3. A class Book which has the following attributes and methods: a. SN: Book serial number - unique integer b. Book title - string c. Book author - string d. Available: Boolean variable that indicate if the book is available or not e. A Constructor that initializes the book title and author. It should also set the book serial number and set available to True. f. An_str_method that make a string of all the book information and then returns it. 4. A class Library which has the following attributes and methods: a. name a string representing the name of the library b. books a list of all books in the library c. borrowed books - a dictionary of the books borrowed. The key should be the book serial number and the value should be the customer ID. d. customers - a list of library customers e. A constructor that initializes the name of the library and creates an empty list of books, an empty list of customers and an empty dictionary of borrowed books. f. add_customer(self, name, membership): add a new customer to the list of customers g. add_book(self, title, author): add a new book to the list of books h. borrow_book(self, book_sn, customer_id): add a new entry to borrowed_books dictionary, the key is the book_sn and the value is customer_id i. get_available_books(self): returns a list of available books j. find_customer_with_membership(self, membership): returns a list of customers with the passed membership type k. is_valid_book_sn(self, sn): check if the passed serial number is valid or not 1. is_valid_customer_id(self, id):: check if the passed customer is valid or not You should design your code in a way that can handle any bad input from the user without crashing (Exception handling). The explained methods should be enough, however, if you need to add more methods or functions, you can do so. Make sure to add comments explaining each function. Write a test code. Create an object (instance) of type Library with the name that you choose for your library. Then, print a menu that allow users to add a customer, add a book, borrow a book, or search for customers with specific membership. If the user chose to borrow a book, then only print the books that are available. Make sure to change the book availability to False if a user borrowed it. If all the books are borrowed, then, print "Sorry, there are no available books to borrow". Refer to the sample output. Note: this is just a sample output, your code should handle any possible input even if it is not illustrated in the sample output. choice: 1 Enter customer name: Sara Choose the membership type: 1. Platinum 2. Silver 3. Gold type: 2 Customer has been added Welcome to the "Your Library Name" Library System What would you like to do? 1. Add a new customer 2. Add a new book 3. Borrow a book 4. Search for customers of specific membership 5. Exit choice: 4 Enter the type of membership you are looking for: 1. Platinum 2. Silver 3. Gold type: 1 Name: Abeer ID: 0 membership is PLATINUM Welkome to the "Your Lahrary Name" Labeary Syatem What would you like to do? 1. Add a nev customer 2. Add a new book 3. Borrow a book 4. Search for customers of specific membership 5. Exalt choice: 4 Enter the type of membership you are looking for. 1. Platinum 2. Silver 3. Cold type: 2 Name: Sara ID: 1 membership is StLVER Welcome to the "Your Labrary Name" Library System What would you like to do? 1. Add a new customer 2. Add a new book 3. Borrow a boolk 4. Search for customers of spedific membership 5. Exit choice: 4 Enter the type of membership you are looking for. 1. Platinum 2. Sillver 3. Gold type: 3 There are no customers with CDLD membershlp Welcome to the "Your Library Name" Library System What would you like to do? 1. Add a nev customer 2. Add a new book 3. Bormow a book 4. Search for customers of spedific membership 5. Exit choice: 2 Enter book title: Starting Dut with Python Enter book author: Tony Gaddis Hook has been added Welcome to the "Your Library Name" Library System What would you like to do? 1. Add a new customer 2. Add a new book 3. Borrow a boolk 4. Search for customers of specific membership 5. Exit choice 2 Enter book title: Data Structures Enter book author. Coodrich Hook has been added Welcome to the "Your Labrary Name" Library System What would you like to do? 1. Add a new customer 2. Add a new book 3. Borrow a bookk 4. Search for customers of specific membership 5. Exit choice: 3 Choose the book that you want to borros from avallable books: Hookk serlal number: 0 Hook title: Starting Out with Python Hook author: Tony Gaddis Available: True Hook serlal number: 1 Book title: Data Structures Book author. Goodrich Available: True Enter the serial number of the bookc: 0 Enter the customer ID: 0 Hook has been borrowed Welcome to the "Your Labrary Name" Library System What would you like to do? 1. Add a new customer Z. Add a new book 3. Borrow a bookk 4. Search for customers of specific membership 5. Exit cholee 3 Choose the bool that you want to borrow from avallable books: Hook serlal number: 1 Hook title: Data Structures Hook author: Goodrich Avallable: True Enter the serlal number of the book: 0 Enter the customer ID: 1 Error .. This book is not available? Welcome to the "Your Labrary Name" Library System What would you like to do? 1. Add a nev customer 2. Add a new book 3. Borrow a book 4. Search for customers of specific membership 5. Eait choice 3 Choose the book that you want to borrow from avallable books: Hooks cerlal number: 1 Hook title: Data Structures Hook author. Goodrich Available: True Enter the serial number of the boolk: 1 Enter the customer ID: I Hook has been borrowed Welcome to the "Your Labrary Name" Library System What would you like to do? 1. Add a new customer 2. Add a nev book 3. Borrow a book 4. Search for customers of specific membership 5. Exit 3 Sorry, there are no avallable boolss to borrow Welcome to the "Your Labrary Name" Library System What would you like to do? 1. Add a new customer 2. Add a new book 3. Borrow a book 4. Search for customers of specific membership 5. Exit choice. 5 Thank you for using the Your Library Name" Whrary System

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

Mastering Real Time Analytics In Big Data A Comprehensive Guide For Everyone

Authors: Lennox Mark

1st Edition

B0CPTC9LY9, 979-8869045706

More Books

Students also viewed these Databases questions