Advertisement
MikelRent

Ex. 8.5

Nov 24th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.06 KB | None | 0 0
  1. package chapter8;
  2. import java.util.Scanner;
  3. public class E85
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         Scanner scan = new Scanner(System.in);
  8.        
  9.         System.out.println("input object's radius:");
  10.         double ra = scan.nextDouble();
  11.  
  12.         System.out.println("input object's height:");
  13.         double he = scan.nextDouble();
  14.        
  15.         Geometry geometry = new Geometry();
  16.        
  17.         System.out.println("volume of cube:");
  18.  
  19.         System.out.println(geometry.cubeVolume());
  20.        
  21.         System.out.println("surface area of cube:");
  22.  
  23.         System.out.println(geometry.cubeSurface());
  24.        
  25.         System.out.println("volume of sphere:");
  26.  
  27.         System.out.println(geometry.sphereVolume());
  28.        
  29.         System.out.println("surface area of sphere:");
  30.  
  31.         System.out.println(geometry.sphereSurface());
  32.  
  33.         System.out.println("volume of cone:");
  34.  
  35.         System.out.println(geometry.coneVolume());
  36.  
  37.         System.out.println("surface area of cone:");
  38.  
  39.         System.out.println(geometry.coneSurface());
  40.        
  41.         System.out.println("volume of cylinder:");
  42.  
  43.         System.out.println(geometry.cylinderVolume());
  44.        
  45.         System.out.println("surface area of cylinder:");
  46.  
  47.         System.out.println(geometry.cylinderSurface());
  48.  
  49.        
  50.        
  51.        
  52.     }
  53. }
  54.  
  55. package chapter8;
  56.  
  57. public class Geometry
  58. {
  59.     private double height;
  60.     private double radius;
  61.    
  62.     public Geometry(double h, double r)
  63.     {
  64.         height = h;
  65.         radius = r;
  66.     }
  67.     public static double cubeVolume(double h)
  68.     {
  69.         return h * h * h;
  70.     }
  71.     public static double cubeSurface(double h)
  72.     {
  73.         return (h * h) * 6;
  74.     }
  75.     public static double sphereVolume(double r)
  76.     {
  77.         return ((r * r * r) * 3.14)/3;
  78.     }
  79.     public static double sphereSurface(double r)
  80.     {
  81.         return 4 * ((r * r) * 3.14);
  82.     }
  83.     public static double coneVolume(double h, double r)
  84.     {
  85.         return 3.14 * (r * r) * (h / 3);
  86.     }
  87.     public static double coneSurface(double h, double r)
  88.     {
  89.         return 3.14 * r * (r + r + h);
  90.     }
  91.     public static double cylinderVolume(double h, double r)
  92.     {
  93.         return 3.14 * (r * r) * h;
  94.     }
  95.     public static double cylinderSurface(double h, double r)
  96.     {
  97.         return 2 * (3.14 * (r * h)) + 2 * ((r * r)* 3.14);
  98.     }
  99.    
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement