Problem

(Geometry: inside a rectangle?) Write a program that draws a fixed rectangle centered a...

(Geometry: inside a rectangle?) Write a program that draws a fixed rectangle centered at (100, 60) with width 100 and height 40. Whenever the mouse is moved, display a message indicating whether the mouse point is inside the rectangle at the mouse point or outside of it, as shown in Figure 16.24b. To detect whether a point is inside a rectangle, use the MyRectangle2D class defined in Programming Exercise 10.13.

Ref Prb:

(Geometry: the MyRectangle2D class) 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 xor 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 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 10.18a).

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

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

F IGURE 10.18 A point is inside the rectangle. (b) A rectangle is inside another rectangle. (c) A rectangle overlaps another rectangle. (d) Points are enclosed inside a rectangle.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT