09 Homework Project.docx

advertisement
09 Homework Project
(All numbers should be of type double)
Create a class called Circle.
It should have an instance field called radius.
It should have another instance field named center of type Point.
It should have a get and a set for radius.
It should have get and set methods for the center. Those methods should use the Point class.
It should have a getArea method that returns the area of the circle.
It should have a three-arg constructor with arguments radius, x, and y.
It should have a two-arg constructor, with arguments radius, and center.
It should have a one-arg constructor with an argument of type Circle that duplicates its argument.
It should have a toString method that returns a string like “Circle, radius=4, center= (4,6)”
It should have an equals method that compares two circles and returns true if the argument circle has
the same radius and location. Extra credit: make it return true if all three numbers are within 1/100 of
one percent of being equal.
Now create the class for the type Point.
This class should have two instance fields called x and y.
Both instance fields should have get and set methods.
The class should have a two-arg constructor.
There should also be a no-arg method getDistance, which returns the distance from the point (0,0) to
(x,y).
The method getDistance should have a one-arg overload, which accepts a point as its argument, and
returns the distance between the argument point and the instance point.
Now in your main program should be in a class called TestCircle. In it, create a circle of radius 5
centered at (4,6).
Use the one-arg constructor to make a copy of this circle. Modify the second circle to have a center at
(-2.5, 7). Use the GetDistance method to calculate the distance between the two circles.
Submit the .java files for classes Circle, Point, and TestCircle to the drop box by midnight, Tuesday,
March 10.
Download