class Item:
def __init__(self, name, code, category, size):
"""
Initializes a generic item with basic details.
Parameters:
name (str): The name of the item.
code (str): The unique code of the item.
category (str): The category (e.g., music, movie, program).
size (float): The size of the item in MB.
"""
self.name = name
self.code = code
self.category = category
self.size = size
def retrieve_information(self):
"""
This method could connect to an internet server to fetch additional details in future versions.
For now, it just returns the basic information of the item.
"""
return f"Name: {self.name}, Code: {self.code}, Category: {self.category}, Size: {self.size}MB"
def __str__(self):
"""
Returns the string representation of the item.
"""
return self.retrieve_information()
class Movie(Item):
def __init__(self, name, code, category, size, director, main_actor, main_actress):
"""
Initializes a Movie object with additional attributes for director, main actor, and actress.
Parameters:
director (str): The director of the movie.
main_actor (str): The main actor of the movie.
main_actress (str): The main actress of the movie.
"""
super().__init__(name, code, category, size)
self.director = director
self.main_actor = main_actor
self.main_actress = main_actress
def retrieve_information(self):
"""
Returns detailed information about the movie.
"""
base_info = super().retrieve_information()
return f"{base_info}, Director: {self.director}, Main Actor: {self.main_actor}, Main Actress: {self.main_actress}"
class MusicFile(Item):
def __init__(self, name, code, category, size, singer, length):
"""
Initializes a MusicFile object with additional attributes for singer and length.
Parameters:
singer (str): The artist or singer.
length (int): The length of the music in seconds.
"""
super().__init__(name, code, category, size)
self.singer = singer
self.length = length
def retrieve_information(self):
"""
Returns detailed information about the music file.
"""
base_info = super().retrieve_information()
return f"{base_info}, Singer: {self.singer}, Length: {self.length} seconds"
class ComputerProgram(Item):
def __init__(self, name, code, category, size, version, language):
"""
Initializes a ComputerProgram object with additional attributes for version and language.
Parameters:
version (str): The version of the program.
language (str): The programming language used to develop the program.
"""
super().__init__(name, code, category, size)
self.version = version
self.language = language
def retrieve_information(self):
"""
Returns detailed information about the computer program.
"""
base_info = super().retrieve_information()
return f"{base_info}, Version: {self.version}, Language: {self.language}"
def display_menu():
"""
Displays the menu for the Catalog application.
"""
print("\nCatalog Menu:")
print("1. Add a Music File")
print("2. Add a Movie")
print("3. Add a Computer Program")
print("4. View All Items")
print("5. Exit")
def main():
# List to store all the catalog items
catalog = []
while True:
display_menu()
choice = input("Enter your choice (1-5): ")
if choice == '1':
# Add a Music File
name = input("Enter the name of the music file: ")
code = input("Enter the code: ")
category = 'Music'
size = float(input("Enter the size (in MB): "))
singer = input("Enter the singer: ")
length = int(input("Enter the length (in seconds): "))
music_file = MusicFile(name, code, category, size, singer, length)
catalog.append(music_file)
elif choice == '2':
# Add a Movie
name = input("Enter the name of the movie: ")
code = input("Enter the code: ")
category = 'Movie'
size = float(input("Enter the size (in MB): "))
director = input("Enter the director: ")
main_actor = input("Enter the main actor: ")
main_actress = input("Enter the main actress: ")
movie = Movie(name, code, category, size, director, main_actor, main_actress)
catalog.append(movie)
elif choice == '3':
# Add a Computer Program
name = input("Enter the name of the program: ")
code = input("Enter the code: ")
category = 'Program'
size = float(input("Enter the size (in MB): "))
version = input("Enter the version: ")
language = input("Enter the programming language: ")
program = ComputerProgram(name, code, category, size, version, language)
catalog.append(program)
elif choice == '4':
# View All Items
print("\nCatalog Items:")
for item in catalog:
print(item)
elif choice == '5':
# Exit the program
print("Exiting the Catalog application...")
break
else:
print("Invalid choice. Please choose a valid option from the menu.")
if __name__ == "__main__":
main()
Output
Catalog Menu:
1. Add a Music File
2. Add a Movie
3. Add a Computer Program
4. View All Items
5. Exit
Enter your choice (1-5): 1
Enter the name of the music file: Song 1
Enter the code: M001
Enter the size (in MB): 3.5
Enter the singer: Artist A
Enter the length (in seconds): 180
Catalog Menu:
1. Add a Music File
2. Add a Movie
3. Add a Computer Program
4. View All Items
5. Exit
Enter your choice (1-5): 4
Catalog Items:
Name: Song 1, Code: M001, Category: Music, Size: 3.5MB, Singer: Artist A, Length: 180 seconds