Lab Performance-F01
Lab Performance-F01
You are to create a simple library management system that models basic library operations
using classes and encapsulation while utilizing dictionaries for storing library items.
Requirements:
1. Class Design:
○ Create a class named Library.
○ The class should have the following attributes:
■ library_name (string)
■ items (dictionary) to store library items, where the key is the item ID
(string) and the value is another dictionary containing:
■ title (string)
■ author (string)
■ is_checked_out (boolean, default: False)
2. Constructor:
○ The constructor (__init__ method) should initialize library_name and an
empty dictionary for items.
3. Methods:
○ Add Item: Create a method named add_item(item_id, title, author)
that:
■ Adds a new item to the items dictionary with the given item ID, title, and
author.
○ Check Out: Create a method named check_out(item_id) that:
■ Checks if the item exists and is not already checked out.
■ Sets is_checked_out to True if the item is available.
■ Returns a success message or an error message if the item is already
checked out.
○ Return Item: Create a method named return_item(item_id) that:
■ Checks if the item exists and is currently checked out.
■ Sets is_checked_out to False if the item is checked out.
■ Returns a success message or an error message if the item is not
checked out.
○ Get Item Info: Create a method named get_item_info(item_id) that:
■ Returns the information of the item (title, author, and check-out status) or
an error message if the item does not exist.
4. Encapsulation:
○ Ensure that direct access to the items dictionary is not possible from outside the
class by using private attributes.
5. Testing:
○ Create an instance of the Library class in the main section of your code.
○ Demonstrate the functionality by performing the following operations:
■ Add several items to the library.
■ Check out an item.
■ Attempt to check out the same item again.
■ Return the item and check its information.
■ Print the information for all items in the library.
Example Output: