from enum import Enum
class Catalog:
def __init__(self, catalog_num: int, title: str, published_date: str):
self.catalog_num = catalog_num
self.title = title
self.published_date = published_date
def __eq__(self, other):
return self.catalog_num == other.catalog_num
def __str__(self):
return f"Catalog Number: {self.catalog_num}, Title: {self.title}, Published Date: {self.published_date}"
class CoverType(Enum):
HARDCOVER = 1
PAPERBACK = 2
class Book(Catalog):
def __init__(self, catalog_num: int, title: str, published_date: str, cover_type: CoverType, subject: str, author: str):
super().__init__(catalog_num, title, published_date)
self.cover_type = cover_type
self.subject = subject
self.author = author
def __str__(self):
return f"Book - {super().__str__()}, Cover Type: {self.cover_type}, Subject: {self.subject}, Author: {self.author}"
class PeriodicalType(Enum):
JOURNAL = 1
MAGAZINE = 2
NEWSPAPER = 3
class Article:
def __init__(self, title: str, author: str, issue_date: str, periodical_title: str):
self.title = title
self.author = author
self.issue_date = issue_date
self.periodical_title = periodical_title
def __str__(self):
return f"Title: {self.title}, Author: {self.author}, Issue Date: {self.issue_date}, Periodical Title: {self.periodical_title}"
class Periodical(Catalog):
def __init__(self, catalog_num: int, title: str, published_date: str, periodical_type: PeriodicalType):
super().__init__(catalog_num, title, published_date)
self.periodical_type = periodical_type
self.articles = []
def __str__(self):
return f"Periodical - {super().__str__()}, Periodical Type: {self.periodical_type}, Articles: {', '.join(map(str, self.articles))}"
def add_article(self, article: Article):
self.articles.append(article)
class FormatType(Enum):
DVD = 1
BLU_RAY = 2
VCD = 3
class Movie(Catalog):
def __init__(self, catalog_num: int, title: str, published_date: str, format_type: FormatType, director: str, actors: int, year: int, length: int):
super().__init__(catalog_num, title, published_date)
self.format_type = format_type
self.director = director
self.actors = actors
self.year = year
self.length = length
def __str__(self):
return f"Movie - {super().__str__()}, Format Type: {self.format_type}, Director: {self.director}, Actors: {self.actors}, Year: {self.year}, Length: {self.length}"
class Library:
def __init__(self, library_name: str):
self.library_name = library_name
self.items = []
def __eq__(self, other):
return self.library_name == other.library_name
def __str__(self):
return f"Library Name: {self.library_name}, Items: {', '.join(map(str, self.items))}"
def add_item(self, item: Catalog):
self.items.append(item)
def remove_item(self, catalog_num: int):
for item in self.items:
if item.catalog_num == catalog_num:
self.items.remove(item)
break
def update_item(self, item: Catalog):
for i, existing_item in enumerate(self.items):
if existing_item == item:
self.items[i] = item
break
def search_by_catalog_num(self, catalog_num: int):
for item in self.items:
if item.catalog_num == catalog_num:
return item
return None
def search_by_title(self, title: str):
result = []
for item in self.items:
if item.title.lower() == title.lower():
result.append(item)
return result
def search_by_article_title(self, title: str):
result = []
for item in self.items:
if isinstance(item, Periodical):
for article in item.articles:
if article.title.lower() == title.lower():
result.append(item)
break
return result
def get_books_by_cover_type(self, cover_type: str):
result = []
for item in self.items:
if isinstance(item, Book) and item.cover_type.name == cover_type:
result.append(item)
return result
def get_movies_by_movie_format(self, format_type: str):
result = []
for item in self.items:
if isinstance(item, Movie) and item.format_type.name == format_type:
result.append(item)
return result
def save_to_db(self):
# Code to save library data to a database
pass
def read_from_db(self):
# Code to read library data from a database
pass
class LibraryApp:
def __init__(self):
self.library = Library("MyLibrary")
def show_program_title(self):
print("Welcome to Library App!")
def show_menu(self):
print("1. Add Item")
print("2. Remove Item")
print("3. Update Item")
print("4. Search By Catalog Number")
print("5. Search By Title")
print("6. Search By Article Title")
print("7. Get Books By Cover Type")
print("8. Get Movies By Format Type")
print("9. Save Data to Database")
print("10. Read Data from Database")
print("11. Exit")
def process_command(self):
while True:
self.show_menu()
command = input("Enter your choice: ")
if command == "1":
self.add_item()
elif command == "2":
self.remove_item()
elif command == "3":
self.update_item()
elif command == "4":
self.search_by_catalog_num()
elif command == "5":
self.search_by_title()
elif command == "6":
self.search_by_article_title()
elif command == "7":
self.get_books_by_cover_type()
elif command == "8":
self.get_movies_by_format_type()
elif command == "9":
self.save_to_db()
elif command == "10":
self.read_from_db()
elif command == "11":
break
else:
print("Invalid command!")
def add_item(self):
catalog_num = int(input("Enter Catalog Number: "))
title = input("Enter Title: ")
published_date = input("Enter Published Date: ")
item_type = input("Enter Item Type (Book/Periodical/Movie): ")
if item_type == "Book":
cover_type = input("Enter Cover Type (HARDCOVER/PAPERBACK): ")
subject = input("Enter Subject: ")
author = input("Enter Author: ")
book = Book(catalog_num, title, published_date, CoverType[cover_type], subject, author)
self.library.add_item(book)
elif item_type == "Periodical":
periodical_type = input("Enter Periodical Type (JOURNUAL/MAGAZINE/NEWSPAPER): ")
periodical = Periodical(catalog_num, title, published_date, PeriodicalType[periodical_type])
self.library.add_item(periodical)
elif item_type == "Movie":
format_type = input("Enter Format Type (DVD/BLU_RAY/VCD): ")
director = input("Enter Director: ")
actors = int(input("Enter Actors: "))
year = int(input("Enter Year: "))
length = int(input("Enter Length: "))
movie = Movie(catalog_num, title, published_date, FormatType[format_type], director, actors, year, length)
self.library.add_item(movie)
else:
print("Invalid item type!")
def remove_item(self):
catalog_num = int(input("Enter Catalog Number: "))
self.library.remove_item(catalog_num)
def update_item(self):
catalog_num = int(input("Enter Catalog Number: "))
item_type = input("Enter Item Type (Book/Periodical/Movie): ")
if item_type == "Book":
cover_type = input("Enter Cover Type (HARDCOVER/PAPERBACK): ")
subject = input("Enter Subject: ")
author = input("Enter Author: ")
book = Book(catalog_num, '', '', CoverType[cover_type], subject, author)
self.library.update_item(book)
elif item_type == "Periodical":
periodical_type = input("Enter Periodical Type (JOURNUAL/MAGAZINE/NEWSPAPER): ")
periodical = Periodical(catalog_num, '', '', PeriodicalType[periodical_type])
self.library.update_item(periodical)
elif item_type == "Movie":
format_type = input("Enter Format Type (DVD/BLU_RAY/VCD): ")
director = input("Enter Director: ")
actors = int(input("Enter Actors: "))
year = int(input("Enter Year: "))
length = int(input("Enter Length: "))
movie = Movie(catalog_num, '', '', FormatType[format_type], director, actors, year, length)
self.library.update_item(movie)
else:
print("Invalid item type!")
def search_by_catalog_num(self):
catalog_num = int(input("Enter Catalog Number: "))
item = self.library.search_by_catalog_num(catalog_num)
if item:
print(item)
else:
print("Item not found!")
def search_by_title(self):
title = input("Enter Title: ")
items = self.library.search_by_title(title)
if items:
for item in items:
print(item)
else:
print("No items found!")
def search_by_article_title(self):
title = input("Enter Article Title: ")
items = self.library.search_by_article_title(title)
if items:
for item in items:
print(item)
else:
print("No items found!")
def get_books_by_cover_type(self):
cover_type = input("Enter Cover Type (HARDCOVER/PAPERBACK): ")
books = self.library.get_books_by_cover_type(cover_type)
if books:
for book in books:
print(book)
else:
print("No books found!")
def get_movies_by_format_type(self):
format_type = input("Enter Format Type (DVD/BLU_RAY/VCD): ")
movies = self.library.get_movies_by_movie_format(format_type)
if movies:
for movie in movies:
print(movie)
else:
print("No movies found!")
def save_to_db(self):
self.library.save_to_db()
print("Data saved to database!")
def read_from_db(self):
self.library.read_from_db()
print("Data loaded from database!")
class CatalogRepository:
def __init__(self, filename: str):
self.filename = filename
def save_items(self, items: list):
# Code to save catalog items to a file
pass
def get_items(self):
# Code to read catalog items from a file
pass
app = LibraryApp()
app.show_program_title()
app.process_command()
Note: Some parts of the code have been left blank and need to be implemented, such as saving and reading data to/from a database, and saving catalog items to a file in the CatalogRepository class.