Question: Python 3 1. Implement the scale method. class Point: def __init__(self, initX, initY): Create a new point at the given coordinates self.__x =

Python 3

1. Implement the scale method.

class Point:

def __init__(self, initX, initY):

""" Create a new point at the given coordinates """

self.__x = initX

self.__y = initY

def getX(self):

""" Get its x coordinate """

return self.__x

def getY(self):

""" Get its y coordinate """

return self.__y

def __str__(self):

""" Return a string representation of the point """

return "({}, {})".format(self.__x, self.__y)

def scale(self, val):

""" Return a new point that is self multiplied by val """

if __name__ == "__main__":

import test

2. We can represent a rectangle by knowing three things: the location of its lower left corner (its starting point), its width, and its height. Write a class definition and constructor method for a Rectangle class (after the definition for the Point class) using this idea. To instantiate a Rectangle object at location (4,5) with width 6 and height 5, we would do the following:

r = Rectangle(Point(4, 5), 6, 5) 

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

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!