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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!