Question: Using Python 3 Programming: State a class Rectangle that has three instance variables: a point (an object of the class Point previously defined, corresponding to
Using Python 3 Programming:
State a class Rectangle that has three instance variables: a point (an object of the class Point previously defined, corresponding to the left bottom corner), a rational width and a rational height.
Implement in this class a constructor with three arguments, a point and two rational values, to be assigned to the three instance variables. No default values should be stated (the constructor must be called with three arguments).
Write a method named perimeter that returns the perimeter of the rectangle.
Write a method named area that returns the area of the rectangle.
Write a method named getOrigin that returns a reference to the point rep- resenting the left bottom corner of the rectangle.
Write a method named toString that returns a string containing, on the same line, the string representing the bottom left corner, followed by the rectangle width and height, formatted as follows (the values will di er depending on each object):
(0.0,0.0), L=2, H=5.5
The class point previously defined:
class Point: def __init__(self, initX, initY): self.x = initX self.y = initY def getX(self): return self.x def getY(self): return self.y def setX(self, x): self.x = x def setY(self, y): self.y = y def toString(self): return "({}, {})".format(self.x, self.y) Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
