A bounding rectangle is the minimum rectangle that encloses a set of points in a two-dimensional plane,

Question:

A bounding rectangle is the minimum rectangle that encloses a set of points in a two-dimensional plane, as shown in Figure. Write a method that returns a bounding rectangle for a set of points in a two-dimensional plane, as follows:

(d) Points are enclosed inside a rectangle.

public static MyRectangle2D getRectangle(double[][] points)

The Rectangle2D class is defined in Exercise. Write a test program that prompts the user to enter five points and displays the bounding rectangle’s center, width, and height. Here is a sample run:

Define the MyRectangle2D class that contains:

■ Two double data fields named x and y that specify the center of the rectangle with getter and setter methods. (Assume that the rectangle sides are parallel to x- or y- axes.)

■ The data fields width and height with getter and setter 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 the 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 this rectangle (see Figure).

A point is inside the rectangle.

■ A method contains(MyRectangle2D r) that returns true if the specified rectangle is inside this rectangle (see Figure 10.24b).

(b) A rectangle is inside another rectangle.

■ A method overlaps(MyRectangle2D r) that returns true if the specified rectangle overlaps with this rectangle (see Figure).

(c) A rectangle overlaps another rectangle.

Draw the UML diagram for the class and then implement the class. Write a test program that creates a MyRectangle2D object r1 (new MyRectangle2D(2, 2, 5.5, 4.9)), displays its area and perimeter, and displays the result of r1.contains(3, 3), r1.contains(new MyRectangle2D(4, 5, 10.5, 3.2)), and r1.overlaps(new MyRectangle2D(3, 5, 2.3, 5.4)).

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: