Exercise
Class Geometricshapes
Objective
Develop a Python project with the required classes, organizing them into separate files, according to this class diagram.
Example Python Exercise
Show Python Code
# PhotoAlbum class definition
class PhotoAlbum:
def __init__(self, page_count=16):
# Initialize the album with a default or specified page count
self.__pageCount = page_count # Private attribute for page count
def getPageCount(self):
# Return the total number of pages in the album
return self.__pageCount
# LargePhotoAlbum class definition (inherits from PhotoAlbum)
class LargePhotoAlbum(PhotoAlbum):
def __init__(self):
# Initialize the large photo album with a default of 64 pages
super().__init__(64) # Calls the constructor of PhotoAlbum with 64 pages
# Test class to demonstrate the functionality
class AlbumTest:
@staticmethod
def Main():
# Create a PhotoAlbum with the default constructor (16 pages)
album1 = PhotoAlbum()
print(f"Album 1 has {album1.getPageCount()} pages.")
# Create a PhotoAlbum with 24 pages
album2 = PhotoAlbum(24)
print(f"Album 2 has {album2.getPageCount()} pages.")
# Create a LargePhotoAlbum (64 pages)
large_album = LargePhotoAlbum()
print(f"Large PhotoAlbum has {large_album.getPageCount()} pages.")
# Main entry point for the program
if __name__ == '__main__':
# Run the test class to demonstrate the functionality
AlbumTest.Main()
Output
python photo_album.py
Album 1 has 16 pages.
Album 2 has 24 pages.
Large PhotoAlbum has 64 pages.
Share this Python Exercise