Question

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 - you can assume uniqueness, you don't have to enforce it
  • title - cannot be assumed to be unique
  • location - a LibraryItem 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 LibraryItem can only be requested by one Patron at a time
  • date_checked_out - when a LibraryItem is checked out, this will be set to the current_date of the Library
  • init method - takes an id_code, and title; checked_out_by and requested_by should be initialized to None; a new LibraryItem's location should be on the shelf
  • get and set methods

Book/Album/Movie:

  • These three classes all inherit from LibraryItem.
  • 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.
  • All three will have an additional field. For Book, it's a string field called author. For Album, it's a string field called artist. For Movie, it's a string field called director. There will also need to be get methods to return the values of these fields.

Patron:

  • id_num - 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 list of LibraryItems that a Patron currently has checked out
  • fine_amount - how much the Patron owes the Library in late fines (measured in dollars); this is allowed to go negative
  • init method - takes an idNum and name
  • get and set methods
  • add_library_item - adds the specified LibraryItem to checked_out_items
  • remove_library_item - removes the specified LibraryItem 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:

  • holdings - a list of the LibraryItems in the Library
  • members - a list of the Patrons in the Library
  • current_date - stores the current date represented as an integer number of "days" since the Library object was created
  • a constructor that initializes the current_date to zero
  • add_library_item - adds the parameter to holdings
  • add_patron - adds the parameter to members
  • get_library_item - returns the LibraryItem corresponding to the ID parameter, or None if no such LibraryItem is in the holdings
  • get_patron - returns the Patron corresponding to the ID parameter, or None if no such Patron is a member
  • In check_out_library_item, return_library_item and request_library_item, check the listed conditions in the order given - for example, if check_out_library_item is called with an invalid LibraryItem ID and an invalid Patron ID, it should just return "item not found".
  • check_out_library_item
    • if the specified LibraryItem is not in the Library's holdings, return "item not found"
    • if the specified Patron is not in the Library's members, return "patron not found"
    • if the specified LibraryItem is already checked out, return "item already checked out"
    • if the specified LibraryItem is on hold by another Patron, return "item on hold by other patron"
    • otherwise update the LibraryItem's checkedOutBy, dateCheckedOut and Location; if the LibraryItem was on hold for this Patron, update requestedBy; update the Patron's checkedOutItems; return "check out successful"
  • return_library_item
    • if the specified LibraryItem is not in the Library's holdings, return "item not found"
    • if the LibraryItem is not checked out, return "item already in library"
    • update the Patron's checkedOutItems; update the LibraryItem's location depending on whether another Patron has requested it (if so, it should go on the hold shelf); update the LibraryItem's checkedOutBy; return "return successful"
  • request_library_item
    • if the specified LibraryItem is not in the Library's holdings, return "item not found"
    • if the specified Patron is not in the Library's members, return "patron not found"
    • if the specified LibraryItem is already requested, return "item already on hold"
    • update the LibraryItem's requestedBy; if the LibraryItem is on the shelf, update its location to on hold; return "request successful"
  • pay_fine
    • takes as a parameter the amount that is being paid (not the negative of that amount)
    • if the specified Patron is not in the Library's members, return "patron not found"
    • use amendFine to update the Patron's fine; return "payment successful"
    • increment_current_date
    • increment current date; increase each Patron's fines by 10 cents for each overdue LibraryItem they have checked out (using amendFine)

Note - a LibraryItem 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("123", "War and Peace", "Tolstoy")
      b2 = Book("234", "Moby Dick", "Melville")
      b3 = Book("345", "Phantom Tollbooth", "Juster")
      p1 = Patron("abc", "Felicity")
      p2 = Patron("bcd", "Waldo")
      lib = Library()
      lib.add_library_item(b1)
      lib.add_library_item(b2)
      lib.add_library_item(b3)
      lib.add_patron(p1)
      lib.add_patron(p2)
      lib.check_out_library_item("bcd", "234")
      for i in range(7):
         lib.increment_current_date()
      lib.check_out_library_item("bcd", "123")
      lib.check_out_library_item("abc", "345")
      for i in range(24):
         lib.increment_current_date()
      lib.pay_fine("bcd", 0.4)
      p1Fine = p1.get_fine_amount()
      p2Fine = p2.get_fine_amount()

This example obviously doesn't include all of the functions described above. 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 LibraryItem, there are six hypothetical changes in location. Are all six possible according to these specifications?

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

Solution for the above problem statement

### Implementation of LibraryItem Class
class LibraryItem():
id_code=''
title = ''
location = ''
checked_out_by = ''
requested_by = ''
date_checked_out = 0
  
def __init__(self,code,title_l):
self.id_code = code
self.title = title_l
self.location = "ON_SHELF"
self.checked_out_by = None
self.requested_by = None
self.date_checked_out = 0
  
def set_code(self,code):
self.id_code = code
  
def set_title(self,title_l):
self.title = title_l
  
def set_location(self,loc):
self.location = loc
  
def set_checked_out(self,name):
self.checked_out_by = name
  
def set_requested_by(self,requested_by_name):
self.requested_by = requested_by_name
  
def set_date_checked_out(self,day):
self.date_checked_out = day
  
  
def get_code(self):
return self.id_code
  
def get_title(self):
return self.title
  
def get_location(self):
return self.location
  
def get_checked_out(self):
return self.checked_out_by
  
def get_requested_by(self):
return self.requested_by
  
def get_date_checked_out(self):
return self.date_checked_out

### Implementation of Book Class
class Book(LibraryItem):
author = ''

def set_name(self,name):
self.author = name
  
def get_name(self):
return self.author


def get_check_out_length(self):
return 21

### Implementation of Album Class
class Album(LibraryItem):
  

artist = ''
def set_artist(self,name):
self.artist = name

def get_artist(self):
return self.artist

def get_check_out_length(self):
return 14

### Implementation of Movie Class
class Movie(LibraryItem):

director = ''
def set_director(self,name):
self.director = name

def get_director(self):
return self.director

def get_check_out_length(self):
return 7

### Implementation of Patron Class
class Patron():
id_num = ''
name =''
checked_out_items = []
fine_amount = 0
  
def __init__(self,code,n):
self.id_num = code
self.name = n
checked_out_items = []
fine_amount = 0
  
def set_id_num(self,id_number):
self.id_num = id_number
  
def set_name(self,id_name):
self.name = id_name
  
def set_fine_amount(self,amt):
self.fine_amount = amt
  
def get_id_num(self):
return self.id_num
  
def get_name(self):
return self.name
  
def get_fine_amount(self):
return self.fine_amount
  
def add_library_item(self,lib_item):
self.checked_out_items.append(lib_item)
  
def remove_library_item(self,lib_item):
self.checked_out_items.remove(lib_item)
  
def amend_fine(self,num):
self.fine_amount = self.fine_amount+num

### Implementation of Library Class
class Library():
holdings = []
members = []
current_date =0
  
def __init__(self):
self.holdings = []
self.members = []
self.current_date = 0
  
  
def set_current_date(self,day):
self.current_date = day
  
def get_current_date(self,day):
return self.current_date
  
def add_library_item(self,library_item):
self.holdings.append(library_item)
  
def add_patron(self,patron_name):
self.members.append(patron_name)
  
def get_library_item(self,id_lib):
for i in self.holdings:
if(id_lib==i.get_code(id_code)):
return i
  
return None
  
def get_patron(self,id_pat):
for i in self.members:
if(id_pat==i.get_id_num(id_num)):
return i
  
return None
  
def check_out_library_item(self,patron_id,library_id):
if(get_library_item(self,library_id)==None):
return "item not found"
  
if(get_patron(self,patron_id)==None):
return "patron not found"
  
lib = get_library_item(self,library_id)
if(lib.get_location()=="CHECKED_OUT"):
return "item already checked out"
  
if(lib.get_location()=="ON_HOLD_SHELF" and lib.get_requested_by!=patron_id):
return "item on hold by other patron"
  
lib.set_checked_out(patron_id)
lib.set_date_checked_out(self.current_date)
lib.set_location("CHECKED_OUT")
if(lib.get_requested_by()==patron_id):
lib.set_requested_by(None)
  
pat = get_patron(self,patron_id)
pat.add_library_item(self,library_id)
return "check out successful"
  
def return_library_item(self,patron_id,library_id):
lib_item = get_library_item(self,library_id)
if(lib_item == None):
return "item not found"
  
if(lib_item.get_location()!="CHECKED_OUT"):
return "item already in library"
  
pat = get_patron(self,patron_id)
pat.remove_library_item(library_id)
  
if(lib.get_requested_by!=None):
lib.set_location("ON_HOLD_SHELF")
else:
lib.set_location("ON_SHELF")
  
lib.set_checked_out(None)
  
return "return successful"
  
  
  
  
def request_library_item(self,patron_id,library_item_id):
if(get_library_item(self,library_item_id)==None):
return "item not found"
  
if(get_patron(self,patron_id)==None):
return "patron not found"
  
lib = get_library_item(self,library_item_id)
  
if(lib.get_location()=="ON_HOLD_SHELF"):
return "item already on hold"
else:
lib.set_requested_by(patron_id)
if(lib.get_location()=="ON_SHELF"):
lib.set_location("ON_HOLD_SHELF")
return "request successful"
  

  def increment_date(self):
self.current_date = self.current_date +1
  
  
def pay_fine(self,patron_id,amt_pay):
pat=get_patron(self,patron_id)
  
if(pat==None):
return "patron not found"
  
pat.amend_fine(self,amt_pay)
return "payment successful"

Add a comment
Know the answer?
Add Answer to:
You will be writing a Library simulator involving multiple classes. You will write the LibraryItem, Patron,...
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
  • In this assignment you will implement software for your local library. The user of the software...

    In this assignment you will implement software for your local library. The user of the software will be the librarian, who uses your program to issue library cards, check books out to patrons, check books back in, send out overdue notices, and open and close the library. class Calendar We need to deal with the passage of time, so we need to keep track of Java. Declare this variable as private int date within the class itself, not within any...

  • 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...

  • 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...

  • This project is divided into 3 parts: Part 1. Create a new project and download the arrayList and...

    This project is divided into 3 parts: Part 1. Create a new project and download the arrayList and unorderedArrayList templates that are attached. Create a header file for your unorderedSet template and add it to the project. An implementation file will not be needed since the the new class will be a template. Override the definitions of insertAt, insertEnd, and replaceAt in the unorderedSet template definition. Implement the template member functions so that all they do is verify that the...

  • I NEED HELP IN MAZE PROBLEM. Re-write the following program using classes. The design is up...

    I NEED HELP IN MAZE PROBLEM. Re-write the following program using classes. The design is up to you, but at a minimum, you should have a Maze class with appropriate constructors and methods. You can add additional classes you may deem necessary. // This program fills in a maze with random positions and then runs the solver to solve it. // The moves are saved in two arrays, which store the X/Y coordinates we are moving to. // They are...

  • I've posted 3 classes after the instruction that were given at start You will implement and...

    I've posted 3 classes after the instruction that were given at start You will implement and test a PriorityQueue class, where the items of the priority queue are stored on a linked list. The material from Ch1 ~ 8 of the textbook can help you tremendously. You can get a lot of good information about implementing this assignment from chapter 8. There are couple notes about this assignment. 1. Using structure Node with a pointer point to Node structure to...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • Please Implement this code using Java Eclipse. CIS 1068 Assignment 8 Warm Up with Objects Due:...

    Please Implement this code using Java Eclipse. CIS 1068 Assignment 8 Warm Up with Objects Due: Wednesday, March 25 70 points (+ up to 15 extra credit) The purpose of this assignment is to give you practice implementing your own classes. It also provides extra practice with arrays. Task Implement a class Task, which is used to represent a job that should be done. It should contain the following private fields: .name text description of what job should be done...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

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