Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

CL I P COL Astro- L(1-cas0) Lsing *A=2 L sin(0/2)

Answered: 1 week ago