Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

please solve it in python.
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic6 Database Programming

Authors: John W. Fronckowiak, David J. Helda

1st Edition

0764532545, 978-0764532542

More Books

Students also viewed these Databases questions