Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create class Circle2D with the following specifications: Circle2D - x : double - y : double - radius : double +Circle2D( ) +Circle2D(x : double,

Create class Circle2D with the following specifications:

Circle2D

- x : double

- y : double

- radius : double

+Circle2D( )

+Circle2D(x : double, y : double, radius : double)

+ getX( ) : double

+ getY( ) : double

+ getRadius( ) : double

+ getArea( ) : double

+ getPerimeter( ) : double

- distance(x1 : double, y1 : double, x2 : double, y2 :double) : double

+ contains(x : double, y : double) : boolean

+ contains(circle : Circle2D) : boolean

+ overlaps(circle : Circle2D) : boolean

Two private double data fields named x and y that specify the center of the circle with get methods.

A private data field radius with a get method.

A no-arg constructor that creates a default circle with (0, 0) for (x, y) and 1 for radius.

A constructor that creates a circle with the specified x, y, and radius.

A method getArea() that returns the area of the circle.

A method getPerimeter() that returns the perimeter of the circle. Perimeter is circumference.

A method contains(double x, double y) that returns true if the specified point (x, y) is inside this circle (see Figure 10.15a).

A method contains(Circle2D circle) that returns true if the specified circle is inside this circle (see Figure 10.15b).

A method overlaps(Circle2D circle) that returns true if the specified circle overlaps with this circle (see Figure 10.15c).

Please see the textbook for figure 10.15, pg. 403.

Write a test program that creates a

Circle2D object c1 (new Circle2D(2, 2, 5.5))

displays its area and perimeter

displays the result of c1.contains(3, 3)

displays the result of c1.contains(new Circle2D(4, 5, 10.5))

displays the result of c1.overlaps(new Circle2D(3, 5, 2.3)).

TIPS FOR 10.11

How to determine if circles C1 and C2 overlap:

Two circles overlap if the distance between the two centers are less than or equal to the sum of their radii.

i.e. distance(circle1 x-coord, circle1 y-coord, circle2 x-coord, circle 2 y=coord) <=

(the radius of Circle 1 + radius of Circle 2)

How to determine if a C1 is contained within C2:

(The distance between the x,y coordinates of C1 and C2 + the radius of C2) is <= radius of C1

How to determine if a point x1,y1 is contained in a circle, C1:

(The distance of the x,y coordinates of C1 from x1, y1) is <= the radius of C1

//Method distance finds the distance between two points.

private static double distance(double x1, double y1, double x2, double y2) {

return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions

Question

=+What is the extent of the use of each type of IE?

Answered: 1 week ago