Home Top Ad

Write a java program to estimate the Pole Height

Share:

Write a java program to estimate the Pole Height.

(SOURCE CODE)
import java.text.*;
import java.util.*;

class PoleHeight

{
      public static void main( String[] args )
         {
             double height;                          
             double distance;                        
             double alpha;            
             double beta;                
             double alphaRad;            
             double betaRad;                  
          Scanner scanner = new Scanner(System.in);
          scanner.useDelimiter(System.getProperty("line.separator"));

     System.out.print("Angle alpha (in degrees):"); 
     alpha = scanner.nextDouble();
     System.out.print("Angle beta (in degree):");
     beta = scanner.nextDouble();
     System.out.print("Distance between points A and B (ft):");
     distance = scanner.nextDouble();

          alphaRad = Math.toRadians(alpha);       
          betaRad = Math.toRadians(beta);
          height = ( distance * Math.sin(alphaRad) * Math.sin(betaRad) )
                   /
                     Math.sqrt( Math.sin(alphaRad + betaRad)
                   *
                     Math.sin(alphaRad - betaRad) );
          DecimalFormat df = new DecimalFormat("0.000");

          System.out.println("lnln Estimating the height of the pole"  
                               + "\n\n"
                               + "Angle at point A (deg): " + df.format(alpha) + "\n"
                               + "Angle at point B (deg): " + df.format(beta) + "\n"
                               + "Distance between A and B (ft): " + df.format(distance)+ "\n"
                               + "Estimated height (ft): " + df.format(height));
         }
}

No comments