In: Computer Science
PYTHON ?Write a superclass encapsulating a rectangle. A rectangle has two attributes representing the width and the height of the rectangle. It has methods returning the perimeter and the area of the rectangle. This class has a subclass, encapsulating a parallelepiped, or box. A parallelepiped has a rectangle as its base, and another attribute, its length; it has two methods that calculate and return its area and volume. You also need to include a client class (with the main method) to test these two classes.??
source code
class Rectangle:
def __init__(self,width,height):
self.width=width;
self.height=height;
def perimeter(self):
return 2*(self.height+self.width)
def area(self):
return self.width*self.height
class ParllelPiped(Rectangle):
def __init__(self,width,height,length):
super().__init__(width,height)
self.length=length
def getArea(self): #lateral surface area
return (super().perimeter())*self.length
def getVolume(self):
return (super().area())*self.length
class Test:
def main():
obj=Rectangle(3,4)
print("The area of a rectangle is :")
print(obj.area())
print("The perimeter of a rectangle is:")
print(obj.perimeter())
obj2=ParllelPiped(3,4,2)
print("The lateral surface area is :")
print(obj2.getArea())
print("The volume of ParellelPiped is :")
print(obj2.getVolume())
if __name__ == "__main__":
main()



