Java Reference
In-Depth Information
Enter a point's x- and y-coordinates: 100.5 50.5
The point is not in the triangle
**3.28
( Geometry: two rectangles ) 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.
w 1
w 1
w 2
w 2
h 1
h 1
( x 1, y 1)
( x 1, y 1)
h 2
( x 2, y 2)
h 2
( x 2, y 2)
(a)
(b)
F IGURE 3.9
(a) A rectangle is inside another one. (b) A rectangle overlaps another one.
Here are the sample runs:
Enter r1's center x-, y-coordinates, width, and height: 2.5 4 2.5 43
Enter r2's center x-, y-coordinates, width, and height: 1.5 5 0.5 3
r2 is inside r1
Enter r1's center x-, y-coordinates, width, and height: 1 2 3 5.5
Enter r2's center x-, y-coordinates, width, and height: 3 4 4.5 5
r2 overlaps r1
Enter r1's center x-, y-coordinates, width, and height: 1 2 3 3
Enter r2's center x-, y-coordinates, width, and height: 40 45 3 2
r2 does not overlap r1
**3.29
( Geometry: two circles ) Write a program that prompts the user to enter the center
coordinates and radii of two circles and determines whether the second circle is
inside the first or overlaps with the first, as shown in FigureĀ 3.10. ( Hint : circle2 is
inside circle1 if the distance between the two centers
| r1 - r2 | and circle2
overlaps circle1 if the distance between the two centers <= r1 + r2 . Test your
program to cover all cases.)
Here are the sample runs:
6 =
Enter circle1's center x-, y-coordinates, and radius: 0.5 5.1 13
Enter circle2's center x-, y-coordinates, and radius: 1 1.7 4.5
circle2 is inside circle1
 
 
Search WWH ::




Custom Search