Question: Write a program that prompts the user to enter the center x-, y-coordinates, width, and height of two rectangles and determines whether the second rectangle

Write a program that prompts the user to enter the center x-, y-coordinates, width, and height of two rectangles and determines whether the second rectangle is inside the first or overlaps with the first, as shown in Figure 3.9. Test your program to cover all cases.

wl wl w2 w2 (xl, yl) h1 (x1, yl) h2 (x2, y2)

Here are the sample runs:

h2 (2, 2) h1 (a) (b) Enter rl's center x-, y-coordinates, width,

wl wl w2 w2 (xl, yl) h1 (x1, yl) h2 (x2, y2) h2 (2, 2) h1 (a) (b) Enter rl's center x-, y-coordinates, width, and height: 2.5 4 2.5 43 -Enter Enter r2's center x-, y-coordinates, width, and height: 1.5 5 0.5 3 JEnter r2 is inside rl Enter rl's center x-, y-coordinates, width, and height: 1 2 3 5.5 -Enter Enter r2's center x-, y-coordinates, width, and height: 3 4 4.5 5 r2 overlaps r1 JEnter Enter rl's center x-, y-coordinates, width, and height: 1 2 3 3 -Erter Enter r2's center x-, y-coordinates, width, and height: 40 45 3 2 r2 does not overlap r1 JEnter

Step by Step Solution

3.43 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Output Enter rls x y coordinates width and height 1 2 3 5 5 Enter r2s x y coordinates widt... View full answer

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 Java Programming Questions!