Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the method, areaOfTriangle(). The method will take in the side lengths,

ID: 3753761 • Letter: C

Question

Complete the method, areaOfTriangle(). The method will take in the side lengths, a, b, and c, of a triangle as double values. The method should return the area of the triangle as a double value. Calculate the area using Heron's formula, where S is the semi-perimeter of the triangle:

You may assume the values of a, b, and c are valid, side-lengths of a triangle.

Starter Code:

public class Triangle {
public static double areaOfTriangle(double a, double b, double c) {
//TODO: complete this method
  
}
}

Heron's Formula S= A+B+C 2 Area yS(S - A)(S - B) (S - C)

Explanation / Answer

public class Triangle { public static double areaOfTriangle(double a, double b, double c) { double s = (a + b + c) / 2; return Math.sqrt(s * (s-a) * (s-b) * (s-c)); } public static void main(String[] args) { System.out.println(areaOfTriangle(3, 4, 5)); } }