Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Python Language Here is 8.19: import math class Rectangle2D: def __init__(

ID: 3577988 • Letter: U

Question

Using Python Language

Here is 8.19:

import math

class Rectangle2D:

def __init__(self, x = 0, y = 0, width = 0, height = 0):

self.x = x

self.y = y

self.width = width

self.height = height

def getX(self):

return self.x

def getY(self):

return self.y

def getWidth(self):

return self.width

  

def getHeight(self):

return self.height

def setHeight(self, x):

self.x = x

def setHeight(self, y):

self.y = y

def setWidth(self, width):

self.width = width

def setHeight(self, height):

self.height = height

def getPerimeter(self):

return 2 * (self.width + self.height)

  

def getArea(self):

return self.width * self.height

  

def containsPoint(self, x, y):

return abs(x - self.x) <= self.width / 2 and abs(y - self.y) <= self.height / 2

  

def contains(self, r):

return self.containsPoint(r.x - r.width / 2, r.y + r.height / 2) and

self.containsPoint(r.x - r.width / 2, r.y - r.height / 2) and

self.containsPoint(r.x + r.width / 2, r.y + r.height / 2) and

self.containsPoint(r.x + r.width / 2, r.y - r.height / 2)

  

def overlaps(self, r):

return abs(self.x - r.x) <= (self.width + r.width) / 2 and

abs(self.y - r.y) <= (self.height + r.height) / 2

def __contains__(self, anotherRectangle):

return self.contains(anotherRectangle)

def __lt__(self, secondRectangle):

return self.__cmp__(secondRectangle) < 0

def __le__(self, secondRectangle):

return self.__cmp__(secondRectangle) <= 0

def __gt__(self, secondRectangle):

return self.__cmp__(secondRectangle) > 0

def __ge__(self, secondRectangle):

return self.__cmp__(secondRectangle) >= 0

# Compare two numbers

def __cmp__(self, secondRectangle):

if self.getArea() > secondRectangle.getArea():

return 1

elif self.getArea() < secondRectangle.getArea():

return -1

else:

return 0

(TAinter two rectangles intersect?) Using the Rectangle2D class you defined in Exercise 8.19, write a program that enables the user to specify the location and size of the rectangles and displays whether the two rectangles intersect, as shown

Explanation / Answer

class Rectangle(object):

   

    def __init__(self, width = 1, height = 2):

        self.width = width

        self.height = height

    def Perimeter(self):

        "Return the Perimeter of the rectangle"

        return (2 * self.width) + (2 * self.height)

    def Area(self):

        "Return the area of the rectangle"

        return self.width * self.height

print("Enter your values")

width = 0

height = 0

# read in the input and see if it will convert to int values

# if not, repeat

while width == 0 or height == 0:

    try:

        width = int(input("width " ""))

        height = int(input("height " ""))

    except:

        width = height = 0

R1 = Rectangle(width, height)

print ('R1:', R1.Perimeter(), R1.Area())

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote