Java Reference
In-Depth Information
ȗ
public static double cylinderVolume(double r,
double h)
ȗ
public static double cylinderSurface(double
r, double h)
ȗ
public static double coneVolume(double r,
double h)
ȗ
public static double coneSurface(double r,
double h)
that compute the volume and surface area of a sphere with radius
r
, a
cylinder with circular base with radius
r
and height
h
, and a cone with
circular base with radius
r
and height
h
. Place them into a class
Geometry
. Then write a program that prompts the user for the values of
r
and
h
, calls the six methods, and prints the results.
Exercise P8.6. Solve Exercise P8.5 by implementing classes
Sphere
,
Cylinder
, and
Cone
. Which approach is more object-oriented?
Exercise P8.7. Write methods
public static double
perimeter(Ellipse2D.Double e);
public static double area(Ellipse2D.Double e);
that compute the area and the perimeter of the ellipse
e
. Add these
methods to a class
Geometry
. The challenging part of this assignment is
to find and implement an accurate formula for the perimeter. Why does it
make sense to use a static method in this case?
381
382
Exercise P8.8. Write methods
public static double angle(Point2D.Double p,
Point2D.Double q)
public static double slope(Point2D.Double p,
Point2D.Double q)
that compute the angle between the x-axis and the line joining two points,
measured in degrees, and the slope of that line. Add the methods to the