1. USING JAVA Part 1 (30 points) Creating a Circle Class We are going to be making some interesting art out of lots of c

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

1. USING JAVA Part 1 (30 points) Creating a Circle Class We are going to be making some interesting art out of lots of c

Post by answerhappygod »

1. USING JAVA
Part 1 (30 points) Creating a Circle Class
We are going to be making some interesting art out of lots of
circles. But
before we can do this, we will first need to create a Circle class
which
will hold the information about a circle and provide methods to
test if
one circle intersects another circle.
Create a new java class Circle. This class will not be static, it
will
not have a main() method, and it will not have static methods.
Instead we
are going to be creating Circle objects and then call the instance
methods
on these objects.
Your class should have the following (non-static and
non-private) instance
variables:
• x, y - the coordinates of the center of the circle
• radius - the radius of the circle
Your class should implement the following public methods:
• Circle(int x, int y, int radius) - the constructor method
specifying
the center and radius
• public boolean isInside(Circle c2) - test if this circle is
entirely
inside circle c2 (true if tangent but inside)
• public boolean isOutside(Circle c2) - test if this circle
is
entirely outside circle c2 (true if tangent but outside)
• public boolean isIntersecting(Circle c2) - test if this
circle
intersects circle c2 (false if tangent)
• public void fill(Graphics g) - using the graphics context g,
draw
this circle filled in solid
• public void draw(Graphics g) - using the graphics context g, draw
the
perimeter of this circle
Hints:
• Remember that instance methods are invoked by first specifying
a
particular object, e.g. circleA.isInside(circleB). In this
example
circleA's instance variables can be directly referred to as x, y,
and
radius. The parameter circleB's instance variables are referred
to
as circleB.x, circleB.y, and circleB.radius.
• Calculating if one circle is inside, outside, or intersecting
another
is a simple comparison of the distance between the centers of
the
circles and the radii of the circles. Use the Pythagorean
Theorem
for calculating the distance between 2 points. Draw a few
diagrams
and the relationship should be clear.
• In drawing the circles remember that Java's drawOval()
routine
specifies the upper left corner and the width and height of
the
rectangle containing the oval. When drawing a circle, you will
need
to calculate these drawing parameters based on the circle's
center
and radius.
Testing:
Download the files CircleTester.java and DrawingPanel.java and copy
them
into your project.
Go ahead and look at CircleTester.java, but DO NOT MODIFY THIS
FILE!
You will test your Circle class by running the CircleTester
class. It has
a main() method, and it will use your Circle class to create
Circle
objects, test them for intersections and draw the figure shown
below. When
your Circle class is finished, its output should exactly match the
diagram
shown below. You can start testing your Circle class as soon as you
have
the constructor and draw methods written. A common development
technique
is to create "stub methods" for any unfinished methods (e.g.
isInside,
isOutside, and isIntersecting) that simply return false. This
allows the
code to be compiled and tested incrementally as each method is
completed.
2.
Part 2 (20 Points) Cool Circle Art
Now create a new program CircleArt.java to create a drawing similar
to
this one.
Here are the design requirements:
1. Create a DrawingPanel of size 400 x 400.
2. Create a Circle object called bigCircle centered and with radius
150,
but do not draw it.
3. There will be two zones: inside the bigCircle and outside
the
bigCircle.
4. In a loop, create 10000 random Circle object, each with a
random
location within the panel and a random radius from 1 to 20.
5. If a circle is inside the bigCircle, draw just its outline, and
draw
it with a random color (but not entirely random). There should
be
some clearly distinct color trait. For mine I set the red
component
of the color to 255, and set the other 2 components to random
values.
6. If a circle is outside the bigCircle, draw a filled circle with
a
random color, but use a distinctly different set of colors than
for
the inside circles.
7. Just discard any circles that intersect the bigCircle.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply