You are on page 1of 2

Exercise – Refining the Circle Class

In this lab, you are going to continue working with Circle and CircleTester classes. Add
the following methods:

a) public boolean isConcentric(Circle anotherCircle)


The method isConcentric returns true when the circle executing the method has
the same center as anotherCircle and its radius is less than the radius of
anotherCircle.
b) public double distance(Circle anotherCircle)
This method returns the distance between the centers of the circle executing the
method and anotherCircle. Let (x,y) and (xa,ya) be the centers of the circle
executing the method and anotherCircle respectively, the distance between their
centers is computed as follows:
x − xa)2 + (y − ya)2
(

Use the method sqrt of the class Math to compute the square root of a number in
the following manner:

double number=3.5;
double sqrtNumber = Math.sqrt(number);
double aSqrt = Math.sqrt(number + 22);

c) public boolean intersects(Circle anotherCircle)


The method intersects returns true when the circle executing the method and
anotherCircle intersect. Two circles intersect if the distance between the centers
of the two circles is less than the sum of their radius. Your method must call the
method distance to obtain the distance between the two circles.
d) Write an equals(Circle anotherCircle) method that returns true when the
radius and centers of both circles are the same. This method can be implemented
in one line.
Enhance the test client class CircleTester that you wrote for the previous lab to use and
test these new methods.

Set a breakpoint on the first line of each method of the class Circle and on the first line of
the tester client CircleTester. Afterwards, run your java project in debug mode to observe
the flow of control when a method is called from the client class.

You might also like