Respuesta :
Answer:
Explanation:
The following code is written in Python. It creates the parent class Shape and the three subclasses Rectangle, Square, and Circle that extend Shape. Shape has the constructor which is empty and the area method which returns 0.0, while the three subclasses take in the necessary measurements for its constructor. Each subclass also has getter and setter methods for each variable and an overriden area() method which returns the shapes area.
class Shape:
def __init__(self):
pass
def area(self):
return 0.0
class Square(Shape):
_length = 0
_width = 0
def __init__(self, length, width):
self._width = width
self._length = length
def area(self):
area = self._length * self._width
return area
def get_length(self):
return self._length
def get_width(self):
return self._width
def set_length(self, length):
self._length = length
def set_width(self, width):
self._width = width
class Rectangle(Shape):
_length = 0
_width = 0
def __init__(self, length, width):
self._width = width
self._length = length
def area(self):
area = self._length * self._width
return area
def get_length(self):
return self._length
def get_width(self):
return self._width
def set_length(self, length):
self._length = length
def set_width(self, width):
self._width = width
class Circle(Shape):
_radius = 0
def __init__(self, radius):
self._radius = radius
def area(self):
area = 2 * 3.14 * self._radius
return area
def get_radius(self):
return self._radius
def set_radius(self, radius):
self._radius = radius