Exemplo n.º 1
0
def main():
    """
    Displays a menu and lets user add, remove, display, checkout, return and find items in a library catalog.
    """
    catalogue = Catalogue()

    # book1 = Book("title1", 22323, "author", 4)
    # dvd1 = Dvd("dvdt", 1111, "jurassic", 2, "sept 2", "japan")
    # catalogue.add_item(book1)
    # catalogue.add_item(dvd1)

    while True:
        print(""" ======LIBRARY MENU=======
            1. Add Item
            2. Remove item 
            3. Display all items
            4. Checkout item 
            5. Return item 
            6. Find item 
            7. Exit
            """)
        choice = int(input("Enter Choice:"))
        if choice == 1:
            catalogue.add_item(catalogue)
        elif choice == 2:
            user_input = int(input("enter call number: "))
            catalogue.remove_item(user_input)
        elif choice == 3:
            catalogue.display_available_items()
        elif choice == 4:
            user_input = int(input("enter call number: "))
            catalogue.check_out(user_input)
        elif choice == 5:
            user_input = int(input("enter call number: "))
            catalogue.return_item(user_input)
        elif choice == 6:
            user_input = input("enter title to search: ").capitalize()
            catalogue.search(user_input)
        if choice == 7:
            sys.exit()
Exemplo n.º 2
0
class Library:
    """
    Represent a library that has a collection of items.
    The library can create, search, check out and return items.
    """
    def __init__(self):
        """
        Creates a new library with an empty list of items
        """
        self.myCatalogue = Catalogue()

    def add_item(self):
        """
        Adds a book to the library's collection if the collection
        doesn't already contain the book
        """
        self.myCatalogue.add_item()

    def remove_item(self, call_number):
        """
        Removes a book from the library's book collection
        :param call_number: A book's call number
        :return: Message telling user whether book was successfully
        deleted
        """
        return self.myCatalogue.check_out(call_number)

    def check_out(self, call_number):
        """
        Checks a book out from the library if it exists.
        Everytime a book is checked out, the number of copies available
        of the book is decremented by 1.
        :param call_number: A book's call number
        :return: Message telling user whether the check out was
        successful
        """
        return self.myCatalogue.check_out(call_number)

    def return_item(self, call_number):
        """
        Returns a book to the library's collection if the book exists
        in the collection. Once a book is returned, its number of copies
         available is incremented by 1
        :param call_number: a book's call number
        :return: Message telling user whether the return was successful
        """
        return self.myCatalogue.return_item(call_number)

    def find_item(self, title):
        """
        Search the library's list of items for a title. If the list
        contains the title, return the item
        :param title: title of a item
        :return: the item that matches title from parameter
        """
        return self.myCatalogue.find_item(title)

    def display_available_items(self):
        """
        Prints out the list of available items and their details
        """
        return self.myCatalogue.display_available_items()