Advertisement
Ntrupiano

Chapter 8 exercises

Nov 28th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. //8.3
  2. Public class Geometry
  3. {
  4.     public static void main(String[] args)
  5.     {
  6.      Scanner sc = new Scanner(System.in);
  7.      System.out.print("Enter radius r: ");
  8.          double radius = sc.nextDouble();
  9.      System.out.print("Enter height h: ");
  10.          double height = sc.nextDouble();
  11.      output(radius, height);
  12.     }
  13.     public static public ­static ­double ­cubeVolume(double­ h)
  14.     {
  15.      double Volume = Math.pow(height/3);
  16.      return Volume;
  17.     }
  18.     public static public ­static ­double ­cubeSurfaceArea(double­ h)
  19.     {
  20.      double SurfaceArea = Math.pow(height/2) * 6;
  21.      return SurfaceArea;
  22.     }
  23.     public static double sphereVolume(double radius, double height)
  24.     {
  25.      double volume = Math.PI * Math.pow(radius/2);
  26.      return Volume;
  27.     }
  28.     public static double sphereSurfaceArea(double radius, double height)
  29.     {
  30.      double SurfaceArea = 4 * Math.PI * Math.pow(radius/2);
  31.      return SurfaceArea;
  32.     }
  33.     public static double cylinderVolume(double radius, double height)
  34.     {
  35.      Volume = Math.PI * Math.pow(radius/2) * height;
  36.      return Volume;
  37.     }
  38.     public static double cylinderSurfaceArea(double radius, double height)
  39.     {
  40.      SurfaceArea = 2 * Math.PI * radius * height + 2 * Math.PI * Math.pow(radius/2);
  41.      return SurfaceArea;
  42.     }
  43.     public static double coneVolume(double radius, double height)
  44.     {
  45.      Volume = 1.0/3.0 * Math.PI * Math.pow(radius/2) * height;
  46.      return Volume;
  47.     }
  48.     public static double coneSurfaceArea(double radius, double height)
  49.     {
  50.      SurfaceArea = Math.PI * radius * Math.sqrt(Math.pow(radius/2) * Math.pow(height/2))
  51.      return SurfaceArea;
  52.     }
  53. }
  54.  
  55. //8.13
  56. Public class Numeric
  57. {
  58.     public static double Power(double x, int n)
  59.     {
  60.      if (n > 0 && n%2 == 0)
  61.      {
  62.       Math.pow(x/n) = Math.pow(x,(n/2.0))
  63.      }
  64.      if (n >0 %% n%2 != 0)
  65.      {
  66.       Math.pow(x/n) = Math.pow(x,(n-1))
  67.      }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement