Java Reference
In-Depth Information
Enter a point's x- and y-coordinates:
The point is in the triangle
100.5 25.5
Enter a point's x- and y-coordinates:
The point is not in the triangle
100.5 50.5
**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.11. 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.11
(a) A rectangle is inside another one. (b) A rectangle overlaps another one.
Here are the sample runs:
2.5 4 2.5 43
Enter r1's center x-, y-coordinates, width, and height:
Enter r2's center x-, y-coordinates, width, and height:
r2 is inside r1
1.5 5 0.5 3
1 2 3 5.5
Enter r1's center x-, y-coordinates, width, and height:
Enter r2's center x-, y-coordinates, width, and height:
r2 overlaps r1
3 4 4.5 5
Enter r1's center x-, y-coordinates, width, and height:
Enter r2's center x-, y-coordinates, width, and height:
r2 does not overlap r1
1 2 3 3
40 45 3 2
**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.12. ( 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.)
 
Search WWH ::




Custom Search