Write a complete program to calculate the volumes of a cone and a hollow cylinder. The shape
Question:
Write a complete program to calculate the volumes of a cone and a hollow cylinder. The shape of a hollow cylinder is shown below, where \(r\) is the radius of the inner cylinder and \(R\) is the radius of the outer cylinder:
First, draw a UML diagram similar to Fig. 2.31 for a class named Cone as described below and then write the code to implement the Cone class.
A. The Cone class has two private data members, radius and height, of type double.
B. Write code for a constructor to set the data members to default values of 0.0 .
C. Write code for the accessor methods, getRadius and getHeight, that return the value of the appropriate data member.
D. Write code for the mutator methods, setRadius and setHeight, that each have one formal parameter which is stored as the value of the data member.
E. Write a method named computeVolume to compute the volume of a cone and return the computed volume to the client. The formula to find the volume of a cone is \(\frac{1}{3} \pi r^{2} h\).
Second, draw a UML diagram similar to Fig. 2.31 for a class named HollowCylinder as described below and then write the code to implement the HollowCylinder class.
F. The HollowCylinder class has three private data members, innerRadius, outerRadius, and height, of type double.
G. Write code for a constructor to set the data members to 0.0 .
H. Write code for the accessor methods, getInnerRadius, getOuterRadius, and getHeight, that return the value of the appropriate data member.
I. Write code for the mutator methods, setInnerRadius, setOuterRadius, and setHeight, that each have one formal parameter which is stored as the value of the data member.
J. Write a method named computeVolume to compute the volume of a hollow cylinder and return the computed volume to the client. The formula to find the volume of a hollow cylinder is \(\pi h\left(R^{2}-r^{2}ight)\).
Third, write a client program to test the Cone and HollowCylinder class as defined above. Name this class CalcVolume. The main method should perform the following tasks:
K. Allow the user to enter a radius of the cone.
Step by Step Answer:
Guide To Java A Concise Introduction To Programming
ISBN: 978-3031228414
2nd Edition
Authors: James T. Streib, Takako Soma