Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. /***************************************************************************
  2. *Pyramid.java
  3. *Kamal Shrestha
  4. *
  5. *This class models and evaluates the height , volume and SurfaceArea of
  6. * King Tetrus pyramid.
  7. *****************************************************************************/
  8.  
  9. import java.util.Scanner;
  10.  
  11. public class Pyramid
  12. {
  13. private double edge;
  14. Scanner stdIn = new Scanner(System.in);
  15. private double edgeLength;
  16. private double height;
  17. private double surfaceArea;
  18. private double volume;
  19.  
  20.  
  21.  
  22.  
  23. //****************************************************************************
  24.  
  25. public void initialize()
  26. {
  27. System.out.print("Enter the value for the pyramid's edges: ");
  28. this.edge = stdIn.nextDouble();
  29. } // end initialize
  30.  
  31. public void setEdge(double edge)
  32. {
  33. this.edge = edge;
  34. } // end edge
  35.  
  36. public void printPyramidData()
  37. {
  38. this.edgeLength = this.edge;
  39. this.height = Math.sqrt(2/3) * this.edgeLength ;
  40. this.volume = Math.sqrt(2) / 12 * Math.pow(this.edgeLength, 3);
  41. this.surfaceArea = Math.sqrt(3 * Math.pow(this.edgeLength, 2));
  42.  
  43. // this part prints the desired output.
  44.  
  45. System.out.printf("Edge Length = %.3f ", this.edgeLength);
  46. System.out.printf("Height = %,.3f", this.height);
  47.  
  48. }// end printPyramid
  49.  
  50.  
  51. } // end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement