Results 1 to 9 of 9
Thread: Volume of a sphere problem
 02112011, 06:37 PM #1Member
 Join Date
 Feb 2011
 Posts
 6
 Rep Power
 0
Volume of a sphere problem
Hey, I got this problem for my school lab and I just don't get how to do it.
The problem is this.
"Write a method that takes in the radius of a sphere and returns it's volume the formula is v=4/2*3.14*r^3"
I don't really get how to do this r^3 business I know I have to use pow(double base, double exp) but it is not working for me.
Here is my code so far.
Java Code:public class math() { public double pow(double base, double exponent) { int v = (4/3)*3.14*pow; return v; } }
Last edited by dj_ee3; 02112011 at 06:40 PM.
 02112011, 06:45 PM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,393
 Blog Entries
 7
 Rep Power
 25
'pow' is a method that takes two parameters (as you have described yourself). You are just writing it as 'pow', i.e. no parentheses, no parameters, no nothing. b.t.w. the pow method is implemented as a static method in the Math class, so it is Math.pow(r, 3)
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
 02112011, 06:46 PM #3Senior Member
 Join Date
 Feb 2011
 Posts
 118
 Rep Power
 0
pow()'s not working because you're not passing anything to it.
Try
Java Code:public double getVolumeOfSphere(double radius) { return volume = (4/3) * Math.PI * Math.pow(radius, 3); }
 02132011, 05:51 AM #4Member
 Join Date
 Feb 2011
 Posts
 6
 Rep Power
 0
 02132011, 05:55 AM #5Senior Member
 Join Date
 Feb 2011
 Posts
 118
 Rep Power
 0
 02132011, 05:58 AM #6Member
 Join Date
 Feb 2011
 Posts
 6
 Rep Power
 0
 02132011, 06:01 AM #7Senior Member
 Join Date
 Feb 2011
 Posts
 118
 Rep Power
 0
 02132011, 06:05 AM #8Member
 Join Date
 Feb 2011
 Posts
 6
 Rep Power
 0
I am sorry... So when we do a program in my Java Class we do two types of classes the container classes which contain instance variables to hold the relevant data  getters and setters  methods to support moving data in/out of class (parsing, translation)  limited computations and such
And the driver classes that is a main method that drives the execution of the overall task (aka entry point for execution)  calls to static methods, as with procedural programming  instances of container class objects to hold different data (may be organized in other data structures, e.g. arrays; manipulated to solve overall task)
or simply how to I execute that return volume statement so I can see a result in a terminal window?Last edited by dj_ee3; 02132011 at 06:15 AM.
 02142011, 03:10 AM #9
I understand what you are talking about in regards to a Driver class, many beginner java classes are taught this way. The community has described how to use Math.pow(), are you still stuck with that?
To see the result of a function, you can simply print it:
Java Code:System.out.println(radiusOfASphere(3));
Similar Threads

Volume of Intersection
By afifi in forum Advanced JavaReplies: 0Last Post: 01072011, 11:42 AM 
3D Terrain on Sphere?
By quddusaliquddus in forum Advanced JavaReplies: 1Last Post: 06222009, 11:50 PM 
Volume of AudioClip
By Fedor in forum New To JavaReplies: 0Last Post: 04252009, 04:16 PM 
Help with sphere.java  not coming out correctly
By JavaInLove in forum Java 2DReplies: 3Last Post: 03172009, 09:38 PM 
Please help. Trying to display a sphere.
By aknbad23 in forum New To JavaReplies: 6Last Post: 10072008, 05:37 PM
Bookmarks