Question: USING PYTHON 3: A) add these accessor methods to the Rectangle class: getWidth, getHeight, getStartPoint (it returns a Point object), and __str__. After the class
USING PYTHON 3:
A)
add these accessor methods to the Rectangle class: getWidth, getHeight, getStartPoint (it returns a Point object), and __str__. After the class definitions, instantiate a Rectangle object and use these four methods with it, displaying the results.
B)add a method area to the Rectangle class that returns the area of a Rectangle instance:
C)write a perimeter method in the Rectangle class so that returns the perimeter of a Rectangle instance:
After the class definitions, instantiate a Rectangle object, use the perimeter method, and display the result.
class Point: def __init__(self, initX, initY): """ Create a new point at the given coordinates """ self.__x = initX self.__y = initY
def __str__(self): """ Return a string representation of the point """ return "({}, {})".format(self.__x, self.__y)
# your code goes here class Rectangle: def __init__(self, p, w, h): self.__lower_left = p self.__width = w self.__height = h
r = Rectangle(Point(4, 5), 6, 5)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
