Question

In this project, you will construct an Object-Oriented framework for a library system. The library must...

In this project, you will construct an Object-Oriented framework for a library system. The library must have books, and it must have patrons. The patrons can check books out and check them back in. Patrons can have at most 3 books checked out at any given time, and can only check out at most one copy of a given book. Books are due to be checked back in by the fourth day after checking them out. For every 5 days after the book is checked out, the patron is charged a flat fee of $12. Patrons have an account balance, and they can make payments so as to clear their account. In addition, we will need some helper methods to help the library administrator view the book/patron records, as well as to find specific books/patrons, and also to update the late fees on a daily basis.

First, you must create a Book class with exactly two attributes: name (the name of the book, assumed to be unique) and num avail (the number of available copies). The Book class doesn’t need any methods, just those two attributes.

Second, you must creat a Patron class with three attributes: name (the name of the patron), cobooks (short for “checked out books” will which store the books the patron checks out as a dictionary), and acct bal (which represents the account balance). Only the name needs to be given when creating a Patron, since a new Patron should always start with acct bal equal to 0 and cobooks equal to an empty dictionary {}. The way that cobooks will work is this: remember that a dictionary consists of “key”-“value” pairs. The “keys” will be the books and the “values” will keep track of time. Every time a Patron checks out a book, it will be thrown into the cobooks dictionary as a “key” with ”value” equal to 0. Then, every time a DailyUpdate is run (see below), we increase the “value” by 1, so that the “value” keeps track of how many days the book has been checked out. This way we can decide when to charge a fee or not

In addition, the Patron class must have two methods: PayFees and DailyUpdate. The PayFees method takes as input an amount that the Patron wishes to pay, and that amount is subtracted from the Patron’s acct bal (for our purposes, a positive account balance means you owe money). The DailyUpdate method increases the “value” of all the books in cobooks by 1 and checks to see if the value is divisible by 5. If so, 20 is added to acct bal. Nothing is returned or printed for either of these methods.

Finally, we need a Library class that can put books and patrons together in one system. The Library class has two attributes, patrons and books both of which are initialized as empty lists (we will simply append books and patrons later on in order to create a library catalogue). In addition, the Library class must have the following methods:

1) The CheckOut method takes as input a book and a patron. You can assume the book and patron both exist. However, if the num avail of the book is 0, print “No copies left!”. If the book is already in the patron’s cobooks dictionary, print “You already have this book!”. Also, if the length of the patron’s cobooks dictionary is greater than 2, print “You have checked out the maximum number of books!”. Otherwise, add book to the patron’s cobooks dictionary as a key with value equal to 0, and decrease the num avail of the book by 1.

2) The CheckIn method takes as input a book and a patron. You can assume the book and patron both exist. However, if the book isn’t in the patron’s cobooks dictionary, print “You can’t check in a book that wasn’t checked out!”. Otherwise, use something like pop (look this up) to remove the book from the patron’s cobooks dictionary, and increase the book’s num avail by 1.

3) The DailyUpdate method takes no input, and simply loops through every patron in the patrons list and calls the DailyUpdate method (i.e., the one from the Patron class) on each.

4) The FindPatron method takes as input a name and returns the patron whose name matches the University of Illinois at Chicago, Department of Mathematics, Statistics and Computer Science page 1 MCS 260 Introduction to Computer Science Summer II 2020 given name. If no such patron exists, however, return 0 instead.

5) The FindBook method takes as input a name and returns the book whose name matches the given name. If no such book exists, however, return 0 instead.

6) The ViewRecords method takes no input and simply prints all of the information in the system. Namely, the name of each book is printed along with the number of available copies of each, and the name of each patron is printed along with their account balance, the names of the books they’ve checked out, and how many days its been since they checked out each book. You should test your code as you go. For instance, you might create the Book class, then ensure it works by creating a book object in the shell and checking it has the desired attributes. In order to test your final code and to have a more user-friendly interface, I have created some supplementary code you can copy and paste into your file. You should be able to find it on Blackboard along with this project file. Basically, the supplement allows for an administrator to log in and view records or perform a “Daily update” (which presumably is meant to be done only once a day, but we can run it however many times we want in order to test our code), and it also allows for a patron to log in by name and either view and pay their fines or find a book to either check out or check in. Notice that at the beginning of my code, I create some books and patrons and put them in so that our library isn’t totally empty. Note that if you re-order the inputs for some of the above methods, my code may not work with yours (for instance, when I create a Book I put the name in before the num avail; the order matters). Here’s an example of your code should ideally run along with the supplement:

===== RESTART: C:\Users\ACE\Desktop\UIC\MCS 260 Summer II 2017\P4SOLN.py ===== Welcome to the automated Library system!
1) Log in as Administrator
2) Log in as Patron

Please choose an option above (or enter q to quit): 1 --------------------
Hello Administrator!
1) View Records

2) Perform Daily Update
Please choose an option above (or enter q to logout): 1
Book Records:
Name: Pythons in the Wild,    Copies: 3
Name: Gems and Perls,    Copies: 1
Name: Ada Karenina,    Copies: 4
Name: The Old Man and the C,    Copies: 2
Patron List:
Name: Bob,    Account Balance: 0

Name: Sally,
1) View Records
2) Perform Daily Update
Please choose an option above (or enter q to logout): q Welcome to the automated Library system!
1) Log in as Administrator
2) Log in as Patron
Please choose an option above (or enter q to quit): 2 Please enter your name (or enter q to quit): Bob --------------------
Welcome Bob!

Account Balance: 0

University of Illinois at Chicago, Department of Mathematics, Statistics and Computer Science

page 2

MCS 260 Introduction to Computer Science Summer II 2020

1) Find a book to check out or in
2) View and pay fees
Please choose an option above (or enter q to logout): 1
Enter the name of a book (or enter q to go back): Gems and Perls
1) Check out this book
2) Check in this book
Please choose an option above (or enter q to go back): 1
Enter the name of a book (or enter q to go back): Ada Karenina
1) Check out this book
2) Check in this book
Please choose an option above (or enter q to go back): 1
Enter the name of a book (or enter q to go back): q
Welcome Bob!
1) Find a book to check out or in
2) View and pay fees
Please choose an option above (or enter q to logout): q
Please enter your name (or enter q to quit): Sally --------------------
Welcome Sally!
1) Find a book to check out or in
2) View and pay fees
Please choose an option above (or enter q to logout): 1
Enter the name of a book (or enter q to go back): Pythons in the Wild 1) Check out this book
2) Check in this book
Please choose an option above (or enter q to go back): 1
Enter the name of a book (or enter q to go back): q
Welcome Sally!
1) Find a book to check out or in
2) View and pay fees
Please choose an option above (or enter q to logout): q
Please enter your name (or enter q to quit): q
Welcome to the automated Library system!
1) Log in as Administrator
2) Log in as Patron
Please choose an option above (or enter q to quit): 1 --------------------
Hello Administrator!
1) View Records
2) Perform Daily Update
Please choose an option above (or enter q to logout): 1
Book Records:
Name: Pythons in the Wild, Copies: 2
Name: Gems and Perls, Copies: 0
Name: Ada Karenina, Copies: 3
Name: The Old Man and the C, Copies: 2
Patron List:
Name: Bob, Account Balance: 0

    Gems and Perls checked out for 0 day(s)
    Ada Karenina checked out for 0 day(s)
Name: Sally,    Account Balance: 0
    Pythons in the Wild checked out for 0 day(s)

University of Illinois at Chicago, Department of Mathematics, Statistics and Computer Science

page 3

MCS 260 Introduction to Computer Science Summer II 2020

1) View Records
2) Perform Daily Update
Please choose an option above (or enter q to logout): 2 Performing Daily Update.....
1) View Records
2) Perform Daily Update
Please choose an option above (or enter q to logout): 2 Performing Daily Update.....
1) View Records
2) Perform Daily Update
Please choose an option above (or enter q to logout): 2 Performing Daily Update.....
1) View Records
2) Perform Daily Update
Please choose an option above (or enter q to logout): 2 Performing Daily Update.....
1) View Records
2) Perform Daily Update
Please choose an option above (or enter q to logout): 2 Performing Daily Update.....
1) View Records
2) Perform Daily Update
Please choose an option above (or enter q to logout): 1 Book Records:
Name: Pythons in the Wild, Copies: 2
Name: Gems and Perls, Copies: 0
Name: Ada Karenina, Copies: 3
Name: The Old Man and the C, Copies: 2
Patron List:
Name: Bob, Account Balance: 24

    Gems and Perls checked out for 5 day(s)
    Ada Karenina checked out for 5 day(s)
Name: Sally,    Account Balance: 12
    Pythons in the Wild checked out for 5 day(s)
1) View Records
2) Perform Daily Update
Please choose an option above (or enter q to logout):

What I have so far: Library is acting up

class Book(object):
def __init__(self, name, num_avail=0):
self.name=name
self.num_avail=num_avail

class Patron(object):
def __init__(self, name):
self.name=''
self.cobooks={}
self.acct_bal=0
self.value=0
def PayFees(self,amount):
self.acct_bal=self.acct_bal- amount
def DailyUpdate(self):
self.value=self.value+1
if self.value/5==0:
self.acct_bal=self.acct_bal+20
  
class Library(Book,Patron):
def __init__(self):
self.name=''
self.num_avail=0
self.patrons=[]
self.books=[]
self.books.append(super().__init__(name='',num_avail=0))
super().__init__(self.name)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Book(object):
def _init_(self, name='', num_avail=0):
self.name=name
self.num_avail=num_avail
print(name,num_avail)
class Patron(object):
def _init_(self, name):
self.name=''
self.cobooks={}
self.acct_bal=0
self.value=0
def PayFees(self,amount):
self.acct_bal=self.acct_bal-amount
def DailyUpdate(self):
self.value=self.value+1
if self.value/5==0:
self.acct_bal=self.acct_bal+20
class Library(Book,Patron):
def _init_(self):

self.name=''
self.num_avail=0
self.patrons=[]
self.books=[]
self.books.append(super()._init_(name='',num_avail=0))
super()._init_(self.name)

def CheckOut(self,book,patron):
if self.num_avail==0:
print("No copies left!")
if book in patron.value():
print("You Already have this book!")
if patron.cobooks>2:
print("You have checked out the Maximum Number of Books!")
else:
if patron.cobooks.key()==0:
self.num_avail=self.num_avail-1

def CheckIn(self,book,patron):
if book not in patron.cobooks:
print("You can't check in a book that wasn't checked out!")

def DailyUpdate(self):
pass

def FindPatron(self,name):
if patron.name:
return name
else:
return 0

def FindBook(self,name):
if self.books==name:
return name
else:
return 0

def ViewRecords(self):
print("Book Records:")


if _name=="main_":
library=Library()
library.books.append(Book("Python in the wild",3))
library.books.append(Book("Gems and Perls", 1))
library.books.append(Book("Ada Karenina", 4))
library.books.append(Book("The Old Man and the C", 2))
library.patrons.append(Patron("Bob"))
library.patrons.append(Patron("Sally"))

while True:
print("Welcome to the automated Library System!")
print("1)Log in as Administrator")
print("2)Log in as Patron")
choice=input("Please choose an option above (or enter q to quit):")
if choice=="q":
break
if choice=="1":
print("------------------------------")
print("Hello Administrator!")
while True:
print("1)View Records")
print("2)Perform Daily Update")
choice = input("Please choose an option above for(or enter q to logout):")
if choice=="q":
break
elif choice=="1":
library.ViewRecords()
elif choice=="2":
print("Performing Daily Update.....")
library.DailyUpdate()
if choice=="2":
while True:
name=input("Please enter your name(or enter q to quit):")
if name=="q":
break
patron=library.FindPatron(name)
if patron==0:
print("This patron name is not on file....")

else:
while True:
print("-----------------------------")
print("Welcome {}!".format(patron.name))
print("1)Find a book to check out or in")
print("2)View and pay fees")
choice=input("Please choose an option above(or enter q to logout):")
if choice=="q":
break
elif choice=="1":
while True:
name=input("Enter the name of a book(or enter q to go back):")
if choice=="q":
break
elif choice=="1":
while True:
name=input("Enter the name of a book(or enter q to go back):")
if choice == "q":
break
elif choice == "1":
while True:
book=library.FindBook(name)
if book==0:
print("This book name is not on file....")
else:
print("1)Check out this book")
print("2)Check in this book")
choice=input("Please choose an option above(or enter q to go back):")
if choice=="q":
continue
elif choice=="1":
library.CheckOut(book,patron)
elif choice=="2":
library.CheckIn(book,patron)
elif choice=="2":
print("Your account balance is:{}",format(patron.acct_bal))
amount=float(input("Enter how much you'd like to pay at this time(or enter 0 to go back):"))
patron.PayFees(amount)

Add a comment
Know the answer?
Add Answer to:
In this project, you will construct an Object-Oriented framework for a library system. The library must...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Subject: Java Program You are writing a simple library checkout system to be used by a...

    Subject: Java Program You are writing a simple library checkout system to be used by a librarian. You will need the following classes: Patron - A patron has a first and last name, can borrow a book, return a book, and keeps track of the books they currently have checked out (an array or ArrayList of books). The first and last names can be updated and retrieved. However, a patron can only have up to 3 books checked out at...

  • ERD Diagram Based solely on the description of library operations below (without making up any additional...

    ERD Diagram Based solely on the description of library operations below (without making up any additional facts/requirements) design a data model that avoids update anomalies. You can use text to describe your model if you want. If so be clear as to what columns have primary and foreign keys, as well as what table a FK refers to. You can sketch it out on paper and scan it. You can use Visio. You can use some other tool if you...

  • Case Study:UniversityLibrarySystem This case is a simplified (initial draft) of a new system for the University...

    Case Study:UniversityLibrarySystem This case is a simplified (initial draft) of a new system for the University Library. Of course, the library system must keep track of books. Information is maintained about both book titles and the individual book copies. Book titles maintain information about title, author, publisher, and catalog number. Individual copies maintain copy number, edition, publication year, ISBN, book status (whether it is on the shelf or loaned out), and date due back in. The library also keeps track...

  • The CIS Department at Tiny College maintains the Free Access to Current Technology (FACT) library of...

    The CIS Department at Tiny College maintains the Free Access to Current Technology (FACT) library of e- books. FACT is a collection of current technology e-books for use by faculty and students. Agreements with the publishers allow patrons to electronically check out a book, which gives them exclusive access to the book online through the FACT website, but only one patron at a time can have access to a book. A book must have at least one author but can...

  • The library records the number of books checked out by each person over the course of...

    The library records the number of books checked out by each person over the course of one day, with the following result: Number of books checked out Probabilities 0 20% 1 45% 2 20% 3 10% 4 5% State the random variable Draw a histogram of the number of booked checked out by each patron over the course of one day Find the mean, variance, and standard deviation What is the probability that a patron will check out at least...

  • A library system has three offices: A) a central administrative office, B) the book circulation desk,...

    A library system has three offices: A) a central administrative office, B) the book circulation desk, and C) the media circulation desk. The database is distributed so that patrons who check out primarily books are stored in a fragment with the book information and that the patrons who check out primarily media are stored with the media records. A query was executed at the central office for a list of all patrons who have any type of material that is...

  • You will be writing a Library simulator involving multiple classes. You will write the LibraryItem, Patron,...

    You will be writing a Library simulator involving multiple classes. You will write the LibraryItem, Patron, and Library classes and the three classes that inherit from LibraryItem (Book, Album and Movie). All data members of each class should be marked as private and the classes should have any get or set methods that will 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 -...

  • // C programming Create a system managing a mini library system. Every book corresponds to a...

    // C programming Create a system managing a mini library system. Every book corresponds to a record (line) in a text file named "mylibrary.txt". Each record consists of 6 fields (Book ID, Title, Author, Possession, checked out Date, Due Date) separated by comma: No comma '', "in title or author name. This mini library keeps the record for each book in the library. Different books can share the book "Title". But the "Book ID" for each book is unique. One...

  • IN C++ My project will be a library management system. It will have seven functions. It...

    IN C++ My project will be a library management system. It will have seven functions. It HAS to contain: classes, structures, pointers and inheritance. fix code according to below 1. Add a new book allows the user to enter in book name and book code Book code has to be in # “Invalid book code” “book name has been added to library” book code will be used to borrow books 2. Add a new user must use first user must...

  • The primary keys are underlined. The foreign keys are denoted by asterisks (*). Description of the...

    The primary keys are underlined. The foreign keys are denoted by asterisks (*). Description of the schema: • person — keeps track of the people who borrow books from the library. The attributes contain personal and contact information. • author — keeps track of personal information about authors. • publisher — keeps track of the publisher information. To keep it simple, most of the attributes have been truncated in the sample database. 1 trivial dependencies are things like X→X or...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT