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()
Exemplo n.º 3
0
class Library:
    """
    The Library consists of a list of books and provides an
    interface for users to check out, return and find books.
    """
    def __init__(self, catalogue):
        """
        Initialize the library with a list of books.
        :param catalogue: a list of item objects to create catalogue from.
        """
        self._catalogue = Catalogue(catalogue)

    def display_library_menu(self):
        """
        Display the library menu allowing the user to either access the
        list of books, check out, return, find, add, remove a book.
        """
        user_input = None
        while user_input != 7:
            print("\nWelcome to the Library!")
            print("-----------------------")
            print("1. Display all items")
            print("2. Check Out an item")
            print("3. Return an item")
            print("4. Find an item")
            print("5. Add an item")
            print("6. Remove an item")
            print("7. Quit")
            string_input = input("Please enter your choice (1-7)\n")

            # handle user pressing only enter in menu
            if string_input == '':
                continue

            user_input = int(string_input)

            if user_input == 1:
                self._catalogue.display_available_item()
                user_input = input("Press Enter to continue\n")
            elif user_input == 2:
                call_number = input("Enter the call number of the book"
                                    " you wish to check out.\n")
                self._catalogue.check_out(call_number)
            elif user_input == 3:
                call_number = input("Enter the call number of the book"
                                    " you wish to return.\n")
                self._catalogue.return_item(call_number)
            elif user_input == 4:
                input_title = input("Enter the title of the book.\n")
                found_titles = self._catalogue.find_items(input_title)
                print("We found the following:")
                if len(found_titles) > 0:
                    print(*[title for title in found_titles], sep='\n')
                else:
                    print("Sorry! We found nothing with that title")

            elif user_input == 5:
                self._catalogue.add_item()

            elif user_input == 6:
                call_number = input("Enter the call number of the book\n")
                self._catalogue.remove_item(call_number)

            elif user_input == 7:
                pass
            else:
                print("Could not process the input. Please enter a"
                      " number from 1 - 7.")

        print("Thank you for visiting the Library.")