Question: Problem 4. (Rectangle) Define a data type Rectangle n rectangle py that represents a rectangle using D intervals (ie, Interval objects) to represent its a




Problem 4. (Rectangle) Define a data type Rectangle n rectangle py that represents a rectangle using D intervals (ie, Interval objects) to represent its a (width) and y (height) segments. The data type must support the following API method Rectangle(xint, yint) description a new rectangle r from the given r and y segments (as interval objects) the area of r the perimeter of r does r contain the point (x, y)? does r intersect the rectangle s? the string representation of r as '[xl, x2] x lyl, y2]' r.area r.perimeter) r.contains (x, y) r.intersects (s) str(r) $ python3 rectangle.py 1.01 1.34 0 101 0.7 1.2 .9 1.5 0 1 01 0.7 1.2 .9 1.5 Area ([o.0, 1.0] x [0.0, 1.0]) 1.000000 Perimeter (o.0, 1.0] x [0.0, 1.0])-4.00000o Area [0.7, 1.2] x [0.9, 1.5])0.300000 Perimeter ( [0.7, 1.2] x [0.9, 1.5]) 2.200000 [0.7, 1.2] x [o.9, 1.5] contains (1.010000, 1.340000) to.0, 1.0 x 0.0, 1.0] intersects [0.7, 1.2] x [0.9, 1.5] import stdio import sys from interval import Interval class Rectangle: InII II Represents a rectangle as two (x and y) intervals. def _init__(self, xint, yint): Constructs a new rectangle given the x and y intervals. def area (self); Returns the area of self. def perimeter(self): Returns the perimeter of self. def contains(self, x, y): Returns True if self contains the point (x, y) and False otherwise. def intersects (self, other): Returns True if self intersects other and False gthewis. def -str-(self): Returns a string representation of self. # Test client [DO NOT EDIT]. Reads a floats x and y from the command line and # writes to standard output: all of the rectangles from standard input # (each defined by two pairs of floats) that contain (x, y); and all pairs # of rectangles from standard input that intersect one another. def _main): x float (S.atgY.[1]) y -float(sys.argv.[2] ) rectangles -[l while not stdio.isEmpty): boundi,stdio.readFloat() rboundi -stdio.readFloat() tbound2 -stdio.readFloat() rbound2= stdio. readFloat () rectangles + [Rectangle(Interval(lbound1, rbound1), Interval (lbound2, rbound2))1 for i in range (len (rectangles)): stdiR..Matet('Area(%s) = %f ", rectangles [1], rectangles [1] .area()) stdiRaKritet("Perimeter(%s ) -%f ", rectangles [1], rectangles [i].perimeter()) if rectangles [i].contains(x, y): stdaOnMrateK'%s contains (Af, %f) ", rectangles [i], x, y) for i in range(len(rectangles)): for j in range(i+ 1, len (rectangles)): if rectangles [i].intersects (rectangles [j]): stdiRnMatet('%s intersects %s ", rectangles[i], rectangles[j]) ame----'-main-': main()