Question: please solve it in python. Q1) Inheritance and Polymorphism Create a program that calculates the perimeter and the area of any given 2D shape. The
Q1) Inheritance and Polymorphism Create a program that calculates the perimeter and the area of any given 2D shape. The program should dynamically assign the appropriate calculation for the given shape. The types of shapes are the following: Quadrilateral Square Perimeter: 4XL Area:LXL Rectangle Perimeter: 2+W Area: LxW Circle Perimeter (circumference); 1x Diameter (n = 3.14) Area: (TTXD)/4 Triangle (assume right triangle) Perimeter: a+b+c Area: 0.5 x base x height (note: the base and height are the shorter sides) Provide an abstract class called Shape2D that contains the common methods. Then create the subclasses Quadrilateral, Circle and Triangle, where the last two implement abstract class Shape2D. Class Quadrilateral should be an abstract class and classes Square and Rectangle will extend and implement the abstract class Quadrilateral. Use UML diagram to draw the classes design hierarchy. For each concrete class, create a _str_0 method that returns the string representation of each shape's measurements (eg, Land W for Rectangle, D for circle, etc.) Create a test file (main program) called TestShape2D. In the test file, create an object of each concrete class type lep, square, rectangle, circle and triangle) and test the methods and display their information using the implicie_str_() call. Use hard code for testing (not in terminal). Example Execution (user input in green) Rectangle: 1 - W - 3. Perimeter - 14.0, Area - 12.0 Square: 1-5, Perimeter - 20.0, Area - 25.0 Circle: D = 5, Perimeter 15.70, Area = 19.625 Triangle: a-4, -2, -3, Perimeter - 9.0, Area - 3.0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
