Java Reference
In-Depth Information
You call this method as follows:
Rectangle r3 = r1.intersection(r2);
Write a program
IntersectionPrinter
that constructs two
rectangle objects, prints them, and then prints the rectangle object that
describes the intersection. Then the program should print the result of the
intersection
method when the rectangles do not overlap. Add a
comment to your program that explains how you can tell whether the
resulting rectangle is empty.
Exercise P2.5. In the Java library, a color is specified by its red, green, and
blue components between 0 and 255. Write a program
BrighterDemo
that constructs a
Color
object with red, green, and blue values of 50, 100,
and 150. Then apply the
brighter
method and print the red, green, and
blue values of the resulting color. (You won't actually see the colorȌsee
Section 2.13
on how to display the color.)
Exercise P2.6. Repeat Exercise P2.5, but apply the
darker
method twice
to the predefined object
Color.RED
. Call your class
DarkerDemo
.
Exercise P2.7. The
Random
class implements a random number generator,
which produces sequences of numbers that appear to be random. To
generate random integers, you construct an object of the
Random
class, and
then apply the
nextInt
method. For example, the call
generator.nextInt(6)
gives you a random number between 0 and 5.