public class Sphere
1: // Exercise 6.6: Sphere.java
2: // Calculate the volume of a sphere.
3: import java.util.Scanner;
4:
5: public class Sphere
6: {
7: // obtain radius from user and display volume of sphere
8: public void determineSphereVolume()
9: {
10: Scanner input = new Scanner( System.in );
11:
12: System.out.print( "Enter radius of sphere: " );
13: double radius = input.nextDouble();
14:
15: System.out.printf( "Volume is %f\n", sphereVolume( radius ) );
16: } // end method determineSphereVolume
17:
18: // calculate and return sphere volume
19: public double sphereVolume( double radius )
20: {
21: double volume = ( 4.0 / 3.0 ) * Math.PI * Math.pow( radius, 3 );
22: return volume;
23: } // end method sphereVolume
24: } // end class Sphere
25:
26: /**************************************************************************
27: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
28: * Pearson Education, Inc. All Rights Reserved. *
29: * *
30: * DISCLAIMER: The authors and publisher of this book have used their *
31: * best efforts in preparing the book. These efforts include the *
32: * development, research, and testing of the theories and programs *
33: * to determine their effectiveness. The authors and publisher make *
34: * no warranty of any kind, expressed or implied, with regard to these *
35: * programs or to the documentation contained in these books. The authors *
36: * and publisher shall not be liable in any event for incidental or *
37: * consequential damages in connection with, or arising out of, the *
38: * furnishing, performance, or use of these programs. *
39: *************************************************************************/