Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************************
- *Pyramid.java
- *Kamal Shrestha
- *
- *This class models and evaluates the height , volume and SurfaceArea of
- * King Tetrus pyramid.
- *****************************************************************************/
- import java.util.Scanner;
- public class Pyramid
- {
- private double edge;
- Scanner stdIn = new Scanner(System.in);
- private double edgeLength;
- private double height;
- private double surfaceArea;
- private double volume;
- //****************************************************************************
- public void initialize()
- {
- System.out.print("Enter the value for the pyramid's edges: ");
- this.edge = stdIn.nextDouble();
- } // end initialize
- public void setEdge(double edge)
- {
- this.edge = edge;
- } // end edge
- public void printPyramidData()
- {
- this.edgeLength = this.edge;
- this.height = Math.sqrt(2/3) * this.edgeLength ;
- this.volume = Math.sqrt(2) / 12 * Math.pow(this.edgeLength, 3);
- this.surfaceArea = Math.sqrt(3 * Math.pow(this.edgeLength, 2));
- // this part prints the desired output.
- System.out.printf("Edge Length = %.3f ", this.edgeLength);
- System.out.printf("Height = %,.3f", this.height);
- }// end printPyramid
- } // end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement