Problem

Ellipse program:Java’s API classes make extensive use of inheritance. For example, Sun’s J...

Ellipse program:

Java’s API classes make extensive use of inheritance. For example, Sun’s Java API documentation shows that the java.awt.geom.Ellipse2D package has a class named Double that has these instance variables:

double

heightThe overall height of the Ellipse2D.

double

widthThe overall width of this Ellipse2D.

double

xThe x coordinate of the upper left corner of this Ellipse2D.

double

YThe y coordinate of the upper left corner of this Ellipse2D.

And it has these constructors:

Double()Constructs a new Ellipse2D, initialized to location (0, 0) and size (0, 0).

Double(double x, double y, double w, double h) Constructs and initializes an Ellipse2D from the specified coordinates.

It has accessors for the instance variables, and an initializing method, but that’s about all. Fortunately, this class extends a class called Ellipse2D, which has several other useful methods, including:

boolean

contains(double x, double y) Tests if a specified point is inside the boundary of this Ellipse2D.

boolean

contains(double x, double y, double w, double h) Tests if the interior of this Ellipse2D entirely contains the specified rectangular area.

boolean

intersects(double x, double y, double w, double h) Tests if the interior of this Ellipse2D intersects the interior of a specified rectangular area.

Write a short program in a class called EllipseDriver:

Import java.awt.geom.Ellipse2D.Double, and write a main method that calls the 4-parameter Double constructor to instantiate an ellipse like that shown in the picture below. Then, in println statements, call the superclass’s 2-parameter contains method to show whether the points x=3.5, y=2.5 and x=4.0, y=3.0 are contained within the specified ellipse.

Output:

contains x=3.5, y=2.5? false contains x=4.0, y=3.0? true

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 12
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT