Advertisement
JoshJurban

Exercise 8.5

Nov 25th, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.36 KB | None | 0 0
  1. package chapter8;
  2.  
  3. public class StaticFunctions {
  4.                
  5.         public static double cylinderVolume(double r, double h){
  6.                         double cylinderVolume;
  7.                         double circleArea;
  8.                         circleArea = Math.PI * Math.pow(r, 2);
  9.                         cylinderVolume = circleArea * h;
  10.                         return cylinderVolume;
  11.                 }
  12.                
  13.           public static double cylinderSurface(double r, double h){
  14.                         double cylinderSurface;
  15.                         cylinderSurface = (2 * Math.PI * r * h) + (2 * Math.PI * Math.pow(r, 2));              
  16.                         return cylinderSurface;
  17.                 }
  18.                
  19.                 public static double sphereVolume(double r){
  20.                         double sphereVolume;
  21.                         sphereVolume = (4/3) * Math.PI * Math.pow(r, 3);
  22.                         return sphereVolume;
  23.                 }
  24.                
  25.                 public static double sphereSurface(double r){
  26.                         double sphereSurface;
  27.                         sphereSurface = 4 * Math.PI * Math.pow(r, 2);
  28.                         return sphereSurface;
  29.                 }
  30.                
  31.                  public static double cubeVolume(double h){
  32.                         double cubeVolume;
  33.                         cubeVolume = Math.pow(h, 3);
  34.                         return cubeVolume;
  35.                 }
  36.                  
  37.                 public static double cubeSurface(double h){
  38.                         double cubeSurface;
  39.                         cubeSurface = 6 * (Math.pow(h, 2));
  40.                         return cubeSurface;
  41.                 }
  42.                 public static double coneVolume(double r, double h){
  43.                         double coneVolume;
  44.                         coneVolume = (1/3) * Math.PI * Math.pow(r,2) * h;
  45.                         return coneVolume;
  46.                 }
  47.                 public static double coneSurface(double r, double h){
  48.                         double coneSurface;
  49.                         double pyThag;
  50.                         pyThag = Math.pow(r, 2) + Math.pow(h, 2);
  51.                         coneSurface = (Math.PI * r) * (r + Math.pow(pyThag, .5));
  52.                         return coneSurface;
  53.                 }
  54.                
  55.                
  56.                
  57.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement