| [SOLVED] java program using method call for a cylinder.Is this correct? Write a general-purpose method that uses 2 double parameters corresponding to the cylinder's radius& height & returns the cylinders volume.
Make sure your method is called from main() &correctly returns a value to main(). Have main() display the value returned & test the method by passing various data to it & verifying the returned value.
[code]
import java.util.Scanner;
import java.text.*;
public class cylinderVolume
{
public static void main(String [] args)
{
Scanner input= new Scanner(System.in);
double radius, height, pi =3.14, volume;
System.out.print("Please enter a radius:");
radius= input.nextDouble();
System.out.print("Please enter a height:");
height= input.nextDouble();
volume= computeVolume(radius,height);
System.out.println("The total volume is " + volume);
}
public static double computeVolume(double radius, double height)
double v;
v= Math.pow(radius,2) * height * 3.14;
return v; |