In Python, develop an inheritance hierarchy based upon a Polygon class that has abstract methods area( ) and perimeter( ). To avoid trivial math, implement classes RightTriangle, Square and Rectangle.
Implemented polygon base class with right triangle,square and rectangle as child classes which inherit from polygon class ,getarea and getperimeter are abstract methods
import math
class Polygon:
def getArea(self):
pass;
def getPerimeter(self):
pass;
class RightTriangle(Polygon):
def __init__(self,height,width):
self.__width=width;
self.__height=height;
def getArea(self):
return 0.5*self.__width*self.__height;
def getPerimeter(self):
return
self.__width+self.__height+(math.sqrt((self.__width*self.__width)+(self.__height*self.__height)));
class Square(Polygon):
def __init__(self,side):
self.__side=side;
def getArea(self):
return self.__side*self.__side;
def getPerimeter(self):
return 4*self.__side;
class Rectangle(Polygon):
def __init__(self,length,breadth):
self.__length=length;
self.__breadth=breadth;
def getArea(self):
return self.__length*self.__breadth;
def getPerimeter(self):
return 2*(self.__length+self.__breadth);
print("RightTriangle");
rt=RightTriangle(3,4);
print("Area: "+str(rt.getArea()));
print("Perimeter: "+str(rt.getPerimeter()));
s=Square(5);
print("Square");
print("Area: "+str(s.getArea()));
print("Perimeter: "+str(s.getPerimeter()));
print("Rectangle");
r=Rectangle(5,4);
print("Area: "+str(r.getArea()));
print("Perimeter: "+str(r.getPerimeter()));
Expected output:

In Python, develop an inheritance hierarchy based upon a Polygon class that has abstract methods area(...
Write the definition of an abstract class shape that define two abstract methods and get Area() and getPerlmeter() returning, respectively the area and the perimeter of that shape. Then write the definition and implementation of a derived classes class shape: class Rectangle. Rectangle class defines two private side integer fields and it overrides methods getArea() and getPerimeter() of the shape class.
JAVA: Quadrilateral Inheritance Hierarchy Write an inheritance hierarchy for classes Quadrilateral, Parallelogram, Rectangle, and Square. Use Quadrilateral as the superclass of the hierarchy. Create and use a Point class to represent the points in each shape. Make the hierarchy as deep as possible, i.e. more than two levels. Specify the instance variables and methods for each class. The private instance variables of Quadrilateral should be the x-y coordinate pairs for the four endpoints of the Quadrilateral. A program that instantiates...
java language
Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...
Java code for the following inheritance hierarchy figure..
1. Create class Point, with two private
instance variables x and y that represented for the coordinates for
a point.
Provide constructor for initialising two instance variables.
Provide set and get methods
for each instance variable,
Provide toString method to return formatted
string for a point coordinates.
2. Create class Circle, its inheritance from
Point.
Provide a integer private
radius instance variable.
Provide constructor to
initialise the center coordinates and radius for...
C++ ONLY PLEASE Problem Description: Objective: Create Inheritance Hierarchy to Demonstrate Polymorphic Behavior Create a Rectangle Class Derive a Square Class from the Rectangle Class Derive a Right Triangle Class from the Rectangle Class Create a Circle Class Create a Sphere Class Create a Prism Class Define any other classes necessary to implement a solution Define a Program Driver Class for Demonstration a) Create a Container to hold objects of the types described above b) Create and Add two(2) objects...
Using Python Write the following well-documented (commented) program. Create a class called Shape that has a method for printing the area and the perimeter. Create three classes (Square, Rectangle, and Circle) which inherit from it. Square will have one instance variable for the length. Rectangle will have two instance variables for the width and height. Circle will have one instance variable for the radius. The three classes will have methods for computing the area and perimeter of its corresponding shape....
Write a Python class, Circle, constructed by a radius and two methods which will compute the area and the perimeter of a circle. Include the constructor and other required methods to set and get class attributes. Create instances of Circle and test all the associated methods. Write a Python class, Rectangle, constructed by length and width and a method which will compute the area of a rectangle. Include the constructor and other required methods to set and get class attributes....
Purpose: To write an Object-Oriented application using abstraction, inheritance, encapsulation, and polymorphism to handle an inheritance structure of various shapes. Details: Implement the following Shape hierarchy: a box around each shape name and arrows pointing to the shape from each (Circle, Square, Triangle) Shape Circle Square Triangle Use the following as a guide: The Shape class should be abstract and contain two abstract methods: getArea – Which calculates the area of the shape and returns that value as a...
Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent class to TwoDimensionalShape and ThreeDimensionalShape. The classes Circle, Square, and Triangle should inherit from TwoDimensionalShape, while Sphere, Cube, and Tetrahedron should inherit from ThreeDimensionalShape. Each TwoDimensionalShape should have the methods getArea() and getPerimeter(), which calculate the area and perimeter of the shape, respectively. Every ThreeDimensionalShape should have the methods getArea() and getVolume(), which respectively calculate the surface area and volume of the shape. Every...
IN JAVA Design and code a class hierarchy that demonstrates your understanding of inheritance and polymorphism. Your hierarchy should contain at least 5 classes and one driver program that instantiates each type of object and runs multiple methods on those objects. Inheritance and Polymorphism must be apparent in the project. Please keep in mind that polymorphism was in chapter 37, so you will need to have read both chapters to understand what goes into this project. Bonus if you add...