Assignement: 92 Using Herons Formula to Calculate Area
Code
/// Name: Sean Harrison
/// Period: 7
/// Program name: HeronsFormula Calculator
/// File Name: HeronsFormula.java
/// Date Finished: 3/21/2016
public class HeronsFormula
{
public static void main( String[] args )
{
double a;
a = triangleArea(3, 3, 3);
System.out.println("A triangle with sides 3,3,3 has an area of " + a );
a = triangleArea(3, 4, 5);
System.out.println("A triangle with sides 3,4,5 has an area of " + a );
a = triangleArea( 7, 8, 9);
System.out.println("A triangle with sides 7,8,9 has an area of " + a );
System.out.println("A triangle with sides 5,12,13 has an area of " + triangleArea(5, 12, 13) );
System.out.println("A triangle with sides 10,9,11 has an area of " + triangleArea(10, 9, 11 ) );
System.out.println("A triangle with sides 8,15,17 has an area of " + triangleArea(8, 15, 17) );
System.out.println("A triangle with sides 9,9,9 has an area of " + triangleArea(9, 9, 9) );
///It was fairly easy to add a new measurment in the file with a method.
}
public static double triangleArea ( int a, int b, int c )
{
double s, A;
s = (a+b+c) /2.0;
A = Math.sqrt( s*(s-a)*(s-b)*(s-c) );
return A;
}
}
/// Yes, the output of both files are identical.
/// HeronsFormula.java is 23 lines long, while the other file is a whoping 38 lines of code.
/// It was far easier to change the code in HeronsFormula with methods.
Picture of the output