I was given this program in order to write the program below. I am unsure what they are asking. Can anyone let me know how to set this up. Thanks in advance.
Write a general-purpose method that uses two double precision parameters corresponding to the cylinder's radius and height, repectively, and returns the cylinders volume.
Include the method in a working Java program. Make sure your method is called from main() and correctly returns a value to main(). Have main() display the value returned and test the method by passing various data to it and verifying the returned value.
Is this correct?
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; } }
You haven't said whether or not you've already tried running the program yourself, entering test data and checked to see if the output matches what you were expecting.
It you haven't done that already, I would suggest trying it first. If you have, did you get the results you expected? In which case you've already answered your own question. If you got different results, what were they?