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

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:

h R

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.

h R

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

import javautilScanner class Cone private double radius private double height public Cone thisradius 00 thisheight 00 public double getRadius return t... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction Java Program Questions!