Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems Second East European Symposium Adbis 98 Poznan Poland September 1998 Proceedings Lncs 1475

Authors: Witold Litwin ,Tadeusz Morzy ,Gottfried Vossen

1st Edition

3540649247, 978-3540649243

More Books

Students also viewed these Databases questions

Question

=+7. How has the competition changed within the last three years?

Answered: 1 week ago

Question

What are oxidation and reduction reactions? Explain with examples

Answered: 1 week ago