Question: ( Language is Python ) - Define the MyRectangle 2 D class that contains: o Two double data fields named x and y specify the

(Language is Python)- Define the MyRectangle2D class that contains:
o Two double data fields named x and y specify the center of the rectangle with getter and
setter methods. (Assume that the rectangle sides are parallel to x- or y-axes.)
o The data fields width and height with getter and setter methods.
o A constructor that creates a default rectangle with (0,0) for (x, y) and 1 for both width
and height.
o A method get_area() that returns the area of the rectangle.
o A method get_perimeter() that returns the perimeter of the rectangle.
o A method contain_point(x1, y1) that returns true if the specified point (x1, y1) is inside
this rectangle (see Figure 1a).
o A method contains(rectangle_2d) that returns true if the specified rectangle is inside this
rectangle (see Figure 1b).
o A method overlaps(rectangle_2d) that returns true if the specified rectangle overlaps
with this rectangle (see Figure 1c).
Task I: Draw the UML diagram for the class and then implement the class.
Task II: Write a test program that
creates a MyRectangle2D object r1 with (2,2,5.5,4.9),
displays the area and perimeter of r1,
displays the result of r1.contain_point (3,3),
displays the result of r1.contains(MyRectangle2D(4,5,10.5,3.2)),
and r1.overlaps(MyRectangle2D(3,5,2.3,5.4)).

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!