Introduction: Java Code/Program - Area and Volume of Icosahedron (20 Sided Sphere)

About: Occupation: tech support

A Java program that calculates the area and volume of an icosahedron, which is a 20 sided sphere (also known as a polyhedron).
Uses java.util.Scanner and java.lang.Math classes
File attached.

    // Matt R test Java program
    // Created using BlueJ IDE www.BlueJ.org
    // Program that calculates icosahedron area and volume

 // Import Scanner class
 import java.util.Scanner;
 // Import Math class for square root and power calculations
 import java.lang.Math;
    
    public class MattCalculateIcosahedron
        {
        public static void main(String[] args) 
            {
                System.out.println("Calculate the area and volume of an icosahedron.");
                System.out.println("An icosahedron has 20 sides.");
                System.out.print("Enter the length of an edge: ");
                // Create Scanner object called keyboardinput
                Scanner keyboardinput = new Scanner(System.in);
                // Put input into variable "edgelength"
                double edgelength = keyboardinput.nextDouble();
                System.out.println("===============");
                // Calculate area of icosahedron
                System.out.println("The formula for the area is: 5 * square root of 3 * (side squared)");
                double squarerootof3 = Math.sqrt(3);
                double areaoficosahedron = (5 * squarerootof3) * (Math.pow(edgelength,2));
                System.out.print("The area of the icosahedron is: ");
                System.out.println(areaoficosahedron);
                System.out.println("=============");
                System.out.println("=============");
                System.out.println("Now we will calculate the volume of an icosahedron.");
                System.out.println("The formula for the volume is: (5/12) * (3 + (square root of 5) * [length of edge cubed])");
                double lengthOfEdgeCubed = (Math.pow(edgelength,3));
                System.out.println("Length of edge cubed: " + lengthOfEdgeCubed);
                double squarerootof5 = Math.sqrt(5);
                System.out.println("Square root of 5: " + squarerootof5);
                double squareRootPlusEdgeCubed = squarerootof5 + lengthOfEdgeCubed;
                System.out.println("Square root plus edge cubed is: " + squareRootPlusEdgeCubed);
                double fiveDividedBy12 = 5.0/12.0;
                System.out.println("5 divided by 12 is: " + fiveDividedBy12);
                double volumeoficosahedron = (fiveDividedBy12) * (3 + squarerootof5) * (lengthOfEdgeCubed);
                System.out.println("================");
                System.out.println("The volume of the icosahedron is: " + volumeoficosahedron);
                
        }  // end of public static void main(String[] args)
    
}  // end of public class MattCalculateIcosahedron

Supplies

- BlueJ IDE
- WIndows, Linux or Mac OS X

Step 1: Code

// Created using BlueJ IDE www.BlueJ.org 
// Program that calculates icosahedron area and volume
// Import Scanner class  <br>import java.util.Scanner;  
// Import Math class for square root and power calculations  
import java.lang.Math;
public class MattCalculateIcosahedron         { 
     public static void main(String[] args)      { 
          System.out.println("Calculate the area and volume of an icosahedron.");
          System.out.println("An icosahedron has 20 sides.");
          System.out.print("Enter the length of an edge: ");
// Create Scanner object called keyboardinput
     Scanner keyboardinput = new Scanner(System.in);
// Put input into variable "edgelength"
       double edgelength = keyboardinput.nextDouble();
       System.out.println("===============");
// Calculate area of icosahedron
       System.out.println("The formula for the area is: 5 * square root of 3 * (side squared)");
       double squarerootof3 = Math.sqrt(3);
       double areaoficosahedron = (5 * squarerootof3) * (Math.pow(edgelength,2));
       System.out.print("The area of the icosahedron is: ");
       System.out.println(areaoficosahedron);
       System.out.println("=============");
       System.out.println("=============");
       System.out.println("Now we will calculate the volume of an icosahedron.");
       System.out.println("The formula for the volume is: (5/12) * (3 + (square root of 5) * [length of edge cubed])");         
       double lengthOfEdgeCubed = (Math.pow(edgelength,3));
       System.out.println("Length of edge cubed: " + lengthOfEdgeCubed);
       double squarerootof5 = Math.sqrt(5);
       System.out.println("Square root of 5: " + squarerootof5);
       double squareRootPlusEdgeCubed = squarerootof5 + lengthOfEdgeCubed;
       System.out.println("Square root plus edge cubed is: " + squareRootPlusEdgeCubed);
       double fiveDividedBy12 = 5.0/12.0;
       System.out.println("5 divided by 12 is: " + fiveDividedBy12);
       double volumeoficosahedron = (fiveDividedBy12) * (3 + squarerootof5) * (lengthOfEdgeCubed);                            
       System.out.println("================");
       System.out.println("The volume of the icosahedron is: " + volumeoficosahedron);                          
         }  // end of public static void main(String[] args)   
    }  // end of public class MattCalculateIcosahedron</a><p><a href="http://www.BlueJ.org"></a></p>