# Base class for all catalog items
class CatalogItem:
def __init__(self, name, code, category, size):
"""
Constructor to initialize the name, code, category, and size of the catalog item.
"""
self.name = name
self.code = code
self.category = category
self.size = size
def RetrieveInformation(self):
"""
Placeholder method to retrieve information about the item from an internet server (to be developed later).
"""
print(f"Retrieving information for {self.name} (Code: {self.code})...")
# Later, this will be connected to an internet server to fetch real details.
return f"Information for {self.name} retrieved."
def Play(self):
"""
Placeholder method for playing the item (can be further developed).
"""
print(f"Playing {self.name}...")
def __str__(self):
return f"Name: {self.name}, Code: {self.code}, Category: {self.category}, Size: {self.size}MB"
# Music class inherits from CatalogItem
class Music(CatalogItem):
def __init__(self, name, code, category, size, singer, length):
"""
Constructor for Music, adding singer and length (in seconds) as extra attributes.
"""
super().__init__(name, code, category, size)
self.singer = singer
self.length = length
def Play(self):
"""
Override Play method to play music.
"""
print(f"Playing music '{self.name}' by {self.singer}, length: {self.length} seconds.")
def __str__(self):
return f"{super().__str__()}, Singer: {self.singer}, Length: {self.length} sec"
# Movie class inherits from CatalogItem
class Movie(CatalogItem):
def __init__(self, name, code, category, size, director, main_actor, main_actress):
"""
Constructor for Movie, adding director, main actor, and main actress as extra attributes.
"""
super().__init__(name, code, category, size)
self.director = director
self.main_actor = main_actor
self.main_actress = main_actress
def Play(self):
"""
Override Play method to play movie.
"""
print(f"Playing movie '{self.name}' directed by {self.director}, starring {self.main_actor} and {self.main_actress}.")
def __str__(self):
return f"{super().__str__()}, Director: {self.director}, Main Actor: {self.main_actor}, Main Actress: {self.main_actress}"
# ComputerProgram class inherits from CatalogItem
class ComputerProgram(CatalogItem):
def __init__(self, name, code, category, size, version, developer):
"""
Constructor for ComputerProgram, adding version and developer as extra attributes.
"""
super().__init__(name, code, category, size)
self.version = version
self.developer = developer
def Play(self):
"""
Override Play method to run the computer program.
"""
print(f"Running the program '{self.name}' (Version: {self.version}) developed by {self.developer}.")
def __str__(self):
return f"{super().__str__()}, Version: {self.version}, Developer: {self.developer}"
# Main function to create and display catalog items
if __name__ == "__main__":
# Create arrays to hold different types of catalog items
music_files = [
Music("Song1", "M001", "Music", 5, "Artist1", 210),
Music("Song2", "M002", "Music", 4, "Artist2", 180)
]
movies = [
Movie("Movie1", "MOV001", "Movie", 700, "Director1", "Actor1", "Actress1"),
Movie("Movie2", "MOV002", "Movie", 650, "Director2", "Actor2", "Actress2")
]
computer_programs = [
ComputerProgram("Program1", "CP001", "Software", 300, "1.0", "Dev1"),
ComputerProgram("Program2", "CP002", "Software", 250, "2.0", "Dev2")
]
# Display details of music files
print("Music Files:")
for music in music_files:
print(music)
music.Play() # Play music
print(music.RetrieveInformation())
print()
# Display details of movies
print("Movies:")
for movie in movies:
print(movie)
movie.Play() # Play movie
print(movie.RetrieveInformation())
print()
# Display details of computer programs
print("Computer Programs:")
for program in computer_programs:
print(program)
program.Play() # Run program
print(program.RetrieveInformation())
print()
Output
Music Files:
Name: Song1, Code: M001, Category: Music, Size: 5MB, Singer: Artist1, Length: 210 sec
Playing music 'Song1' by Artist1, length: 210 seconds.
Retrieving information for Song1 (Code: M001)...
Information for Song1 retrieved.
Name: Song2, Code: M002, Category: Music, Size: 4MB, Singer: Artist2, Length: 180 sec
Playing music 'Song2' by Artist2, length: 180 seconds.
Retrieving information for Song2 (Code: M002)...
Information for Song2 retrieved.
Movies:
Name: Movie1, Code: MOV001, Category: Movie, Size: 700MB, Director: Director1, Main Actor: Actor1, Main Actress: Actress1
Playing movie 'Movie1' directed by Director1, starring Actor1 and Actress1.
Retrieving information for Movie1 (Code: MOV001)...
Information for Movie1 retrieved.
Name: Movie2, Code: MOV002, Category: Movie, Size: 650MB, Director: Director2, Main Actor: Actor2, Main Actress: Actress2
Playing movie 'Movie2' directed by Director2, starring Actor2 and Actress2.
Retrieving information for Movie2 (Code: MOV002)...
Information for Movie2 retrieved.
Computer Programs:
Name: Program1, Code: CP001, Category: Software, Size: 300MB, Version: 1.0, Developer: Dev1
Running the program 'Program1' (Version: 1.0) developed by Dev1.
Retrieving information for Program1 (Code: CP001)...
Information for Program1 retrieved.
Name: Program2, Code: CP002, Category: Software, Size: 250MB, Version: 2.0, Developer: Dev2
Running the program 'Program2' (Version: 2.0) developed by Dev2.
Retrieving information for Program2 (Code: CP002)...
Information for Program2 retrieved.