Implement the class and write a test program that creates a


Define the MyRectangle2D class that contains: 

  • Two double data fields named x and y that specify the center of the rectangle with get and set methods. (Assume that the rectangle sides are parallel to the x- or y-axes.) 
  • The data fields width and height with get and set methods. 
  • A no-arg constructor that creates a default rectangle with (0, 0) for (x, y) and 1 for both width and height. 
  • A constructor that creates a rectangle with specified x, y, width, and height. 
  • A method getArea() that returns the area of the rectangle. ? A method getPerimeter() that returns the perimeter of the rectangle. 
  • A method contains (double x, double y) that returns true if the specified point (x, y) is inside the rectangle. See Figure (a) 
  • A method contains (Rectangle2D r) that returns true if the specified rectangle is inside this rectangle. See Figure (b) 
  • A method overlaps (Rectangle2D r) that returns true if the specified rectangle overlaps with this rectangle. See Figure (c)

920_Untitled picture.png

Implement the class and write a test program that creates a Rectangle2D object r1 (new Rectangle2D (2, 2, 5.5, 4.9)), displays its area and perimeter, and displays the results of r1.contains (3, 3), r1.contains (new Rectangle2D (4, 5, 10.5, 3.2)), and r1.overlaps (new Rectangle2D (3, 5, 2.3, 5.4)).

Please note, your implementation will be tested with other test cases too.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Implement the class and write a test program that creates a
Reference No:- TGS01575575

Expected delivery within 24 Hours