Question
Python 3 1. Add these accessor methods to the Rectangle class: getWidth, getHeight, getStartPoint (it returns a Point object), and __str__. After the class definitions,
Python 3
1. 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.
class Rectangle:
def __init__(self, point, width, height):
""" Creates a new rectangle with given left bottom point, width and height"""
self.point = point
self.width = width
self.height = height
r = Rectangle(Point(4,5),6,5)
if __name__ == "__main__":
import test
2. Using the code above, add a method area to the Rectangle class that returns the area of a Rectangle instance
r = Rectangle(Point(3, 8), 10, 5)
testEqual(r.area(), 50)
# codes goes here
3. Using the code above, then write a perimeter method in the Rectangle class so that returns the perimeter of a Rectangle instance:
r = Rectangle(Point(-1, -2), 10, 5)
testEqual(r.perimeter(), 30)
# codes goes here
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started