The Artima Developer Community
Sponsored Link

Java Answers Forum
Volume of a cylinder

1 reply on 1 page. Most recent reply: Jun 6, 2007 2:22 AM by Vincent O'Sullivan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Dorian Lates

Posts: 1
Nickname: shivers20
Registered: Jun, 2007

Volume of a cylinder Posted: Jun 5, 2007 12:22 AM
Reply to this message Reply
Advertisement
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;
}
}


Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: Volume of a cylinder Posted: Jun 6, 2007 2:22 AM
Reply to this message Reply
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?

Flat View: This topic has 1 reply on 1 page
Topic: Volume of a cylinder Previous Topic   Next Topic Topic: a jtapi problem

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use