Question: cs2 final ex. please help quickly python only Question 2 - 20 Marks Closely follow these instructions to create an inheritance structure to represent some

cs2 final ex. please help quickly python only

Question 2 - 20 Marks Closely follow these instructions to create an inheritance structure to represent some 2D shapes. Create a class called Shape. It should have one private instance variable of type integer and named number_of_sides. It should have a constructor that takes one argument, the number of sides. Instantiate the number_of_sides instance variable in the constructor body. Create a method named calculate_area that takes no arguments and just passes (no implementation). Create another method named calculate_perimeter that takes no arguments and just passes (no implementation). Create appropriate getters and setters. Create a class named Rectangle that is a child of Shape. It should have two private instance variables, a float named width and a float named height. Create a constructor that takes three arguments, number_of_sides, width, and height. Fulfill the constructor requirement of the parent class. Implement the calculate_area method. - Area of a rectangle is calculated as: area = width * height Implement the calculate_perimeter method. - Perimeter of a rectangle is calculated as: perimeter = 2(width) + 2(height) Create appropriate getters and setters. Create an appropriate __eq__ method. Create a __str__ method to return a string in the following format (where x is the appropriate value): "A rectangle has x sides | Area = x | Perimeter = x" Create a class named Circle that is a child of Shape. It should have one private instance variable, a float named radius. Create a constructor that takes two arguments, number_of_sides, and radius. Fulfill the constructor requirement of the parent class. Implement the calculate_area method. - Area of a circle is calculated as: area = PI * radius^2 Implement the calculate_perimeter method. - Perimeter (circumference) of a circle is calculated as: perimeter = 2 * PI * radius Create appropriate getters and setters. Create an appropriate __eq__ method. Create a __str__ method to return a string in the following format (where x is the appropriate value): "A circle has x sides | Area = x | Perimeter = x" Create a class named EquilateralTriangle that is a child of Shape. It should have one private instance variable, a float named side_length. Create a constructor that takes two arguments, number_of_sides, and side_length. Fulfill the constructor requirement of the parent class. Implement the calculate_area method. - Area of an equilateral triangle is calculated as: area = side_length^2 * sqrt(3) / 4 - Or by using angles! Implement the calculate_perimeter method. - Perimeter of an equilateral triangle is calculated as: perimeter = side_length * number_of_sides Create appropriate getters and setters. Create an appropriate __eq__ method. Create a __str__ method to return a string in the following format (where x is the appropriate value): "A circle has x sides | Area = x | Perimeter = x" YOUR_NAME YOUR_ID <<<< CHANGE THESE Resources (You can visit these websites only. You cannot click links on the webpage): https://docs.python.org/3/library/math.html?highlight=math#module-math https://www.pythontutorial.net/python-oop/python-__eq__/ """ # DEFINE YOUR CLASSES HERE if __name__ == '__main__': rectangle = Rectangle(4, 4.1, 2.3) print(rectangle) # 4 sides, area=9.43, perimeter=12.8 circle = Circle(1, 3.5) print(circle) # 1 side, area=38.48, perimeter=21.99 equilateralTriangle = EquilateralTriangle(3, 2.8) print(equilateralTriangle) # 3 sides, area=3.39, perimeter=8.40 print() # Now to test your polymorphism! shapes = [ Circle(1, 3.2), # 1 side, area=32.17, perimeter=20.11 Rectangle(4, 2, 2.6), # 4 sides, area=5.20, perimeter=9.20 Circle(1, 8.3), # 1 side, area=216.42, perimeter=52.15 EquilateralTriangle(3, 9.1) # 3 sides, area=35.86, perimeter=27.30 ] for shape in shapes: print(shape) 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!