SurfaceAreaOfCube.java
1    /* 
2     *Program that features two functions to compute the surface area of a cube. 
3     * - The edge length will be read from the standard input string 
4     * - The surface area will be printed to the standard output stream 
5     * - A face of the cube will be modeled as a simple square 
6     */
7    
8    package mathematics;
9    
10   import java.util.Scanner;
11   import shapes.SSquare;
12   
13   public class SurfaceAreaOfCube {
14   
15       public static void main(String[] args) {
16           double edgeLength = edgeLength();
17           double surfaceArea = surfaceArea(edgeLength);
18           System.out.println("surface area = " + surfaceArea);
19       }
20   
21       //Abstraction #1 - refined when you define the method
22       private static double edgeLength() {
23           System.out.print("Please enter the ledge length of the cube: ");
24           Scanner scanner = new Scanner(System.in);
25           double edgeLength = scanner.nextDouble();
26           return edgeLength;
27       }
28   
29       //Abstraction #2 - refined when you define the method
30       private static double surfaceArea(double edgeLength) {
31           SSquare face = new SSquare(edgeLength);
32           int nrOfFaces = 6;
33           double surfaceArea = face.area() * nrOfFaces;
34           return surfaceArea;
35       }
36   }
37