## Question

• A constructor to create a default circle centered at (0,0) with radius 1.

• A constructor with one parameter r that allows the user to create a circle of radius r that will by default be centered at (0,0).

• A constructor with three parameters, the first two give the x- and y-coordinates respectively, and the third is the radius.

• A method with one Circle parameter that will return true if the calling object contains the parameter object, and false otherwise.

• A method with one Circle parameter that will return true if the two circles have intersection of positive area, and false otherwise.

• A method with one Circle parameter that will return true if the two circles are tangent to one another, and false otherwise.

• A method that has one Circle parameter and returns true if the two circles are identical, and false otherwise.

• A method that returns the area (as a double) of the calling object.

• A method that returns the circumference (as a double) of the calling object.

• A method to convert a Class object to a string representation in a form shown by the following example: Center: (1,5) Radius: 8

Your project should have a class that tests the Circle class. This class will include main and should do the following.

1. Write a description informing the user that two circles C1 and C2 will be created based on input from the user.

2. Provide a menu selection to see if the user wishes to use a default circle, specify only the radius, or specify x, y, and radius for C1.

1) Default Circle

2) Specify the radius of a circle centered at (0,0).

3) Enter all information about the circle 3. Based on the input from the previous step create C1

4. Repeat the previous two steps for C2 instead of C1.

5. Print out on separate lines the information for C1 and C2. (Must use toString() ).

6. Print out the strongest of the following that is true (only one should be printed): 1) C1 and C2 are equal 2) C1 contains C2.

3) C2 contains C1.

4) C1 and C2 intersect in positive area.

5) C1 and C2 are tangent. 6) C1 and C2 are disjoint.

7. Ask the user if another pair of circles should be considered. If “yes” begin again at Step 2.

above; otherwise, quit.

The test class must have a static method that asks the user to input the choice of which circle to use; reads the information; and then creates the circle and returns it.

Additional requirements and hints:

• All fields in the Circle class are to be integers (no floats and doubles).

• How do you know whether or not one circle is inside another? - the distance between their centers plus the radius of the smaller is less than or equal to the radius of the larger.

• When do two circles intersect in positive area? – when the distance between their centers is less than the sum of their radii.

• When are two circles tangent? - when the distance between their centers equals the sum of their radii.

• When doing these comparisons, don’t use Math.sqrt, rather work with the squares of quantities. This way everything is integer and comparing for equality doesn’t present the same problems as comparing doubles for equality.

Here is a sample run:

You will be asked for information regarding a pair of circles C1 and C2. After entering the information the circles will be created and information about them reported.

For circle C1:

Enter 1 for default circle;

Enter 2 to specify radius only; Enter 3 to specify center and radius.

Enter your selection: 3

Enter the x coordinate: 5

Enter the y coordinate: 5

Enter the radius: 7

For circle C2:

Enter 1 for default circle;

Enter 2 to specify radius only; Enter 3 to specify center and radius.

Enter your selection: 2

Enter the radius: 1

C1: Center: (5,5) Radius: 7

C2: Center: (0,0) Radius: 1

C1 and C2 intersect

The area of C1 is 153.93804002589985

The circumference of C1 is 43.982297150257104

The area of C2 is 3.141592653589793

The circumference of C2 is 6.283185307179586

Would you like to try another pair (yes or no)?

For circle C1:

Enter 1 for default circle;

Enter 2 to specify radius only; Enter 3 to specify center and radius.

Enter your selection: 2 Enter the radius: 5

For circle C2:

Enter 1 for default circle;

Enter 2 to specify radius only; Enter 3 to specify center and radus.

Enter your selection: 2

Enter the radius: 5

C1: Center: (0,0) Radius: 5

C2: Center: (0,0) Radius: 5

C1 and C2 are equal.

The area of C1 is 78.53981633974483

The circumference of C1 is 31.41592653589793 The area of C2 is 78.53981633974483

The circumference of C2 is 31.41592653589793

Would you like to try another pair (yes or no)? yes

For circle C1:

Enter 1 for default circle; Enter 2 to specify radius only; Enter 3 to specify center and radius.

Enter your selection: 2 Enter the radius: 5

For circle C2:

Enter 1 for default circle; Enter 2 to specify radius only; Enter 3 to specify center and radius.

Enter your selection: 2

Enter the radius: 7

C1: Center: (0,0) Radius: 5

C2: Center: (0,0) Radius: 7

C2 contains C1

The area of C1 is 78.53981633974483

The circumference of C1 is 31.41592653589793

The area of C2 is 153.93804002589985

The circumference of C2 is 43.982297150257104

Would you like to try another pair (yes or no)? yes

For circle C1:

Enter 1 for default circle; Enter 2 to specify radius only; Enter 3 to specify center and radius. Enter your selection: 1

For circle C2: Enter 1 for default circle; Enter 2 to specify radius only; Enter 3 to specify center and radius. Enter your selection: 1

C1: Center: (0,0) Radius: 1

C2: Center: (0,0) Radius: 1

C1 and C2 are equal.

The area of C1 is 3.141592653589793

The circumference of C1 is 6.283185307179586 The area of C2 is 3.141592653589793

The circumference of C2 is 6.283185307179586

Would you like to try another pair (yes or no)? no

## Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class Circle {private int x;

private int y;

private int radius;

/**

* A constructor to create a default circle centered at (0,0) with radius 1.

*/

public Circle() {

x = 0;

y = 0;

radius = 1;

}

/**

* A constructor with one parameter r that allows the user to create

* a circle of radius r that will by default be centered at (0,0)

* @param radius

*/

public Circle(int radius) {

this.x = 0;

this.y = 0;

this.radius = radius;

}...