Java Reference
In-Depth Information
(a)
(b)
(c)
F IGURE 14.49
(a) The program displays an arrow line. (b) Exercise14.21 connects the centers of two filled circles.
(c) Exercise14.22 connects two circles from their perimeter.
*14.21
( Two circles and their distance ) Write a program that draws two filled circles
with radius 15 pixels, centered at random locations, with a line connecting the
two circles. The distance between the two centers is displayed on the line, as
shown in Figure 14.49b.
*14.22
( Connect two circles ) Write a program that draws two circles with radius
15  pixels, centered at random locations, with a line connecting the two circles.
The line should not cross inside the circles, as shown in Figure 14.49c.
*14.23
( Geometry: two rectangles ) Write a program that prompts the user to enter the
center coordinates, width, and height of two rectangles from the command line.
The program displays the rectangles and a text indicating whether the two are
overlapping, whether one is contained in the other, or whether they don't over-
lap, as shown in Figure 14.50. See Programming Exercise 10.13 for checking the
relationship between two rectangles.
(a)
(b)
(c)
F IGURE 14.50
Two rectangles are displayed.
*14.24
( Geometry: Inside a polygon? ) Write a program that prompts the user to enter
the coordinates of five points from the command line. The first four points form a
polygon, and the program displays the polygon and a text that indicates whether
the fifth point is inside the polygon, as shown in Figure 14.51a. Hint: Use the
Node 's contains method to test whether a point is inside a node.
 
Search WWH ::




Custom Search