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

Create a Java program TriangleStat.java that asks the user to input the lengths

ID: 3669149 • Letter: C

Question

Create a Java program TriangleStat.java that asks the user to input the lengths of three sides of a triangle. After receiving the three values, your program should provide answers for each of the following questions: Is it really a triangle? If one side is longer than the sum of the other two sides, then it is not. Is it a right triangle? That is, does it satisfy the Pythagorean Theorem? Is it an equilateral triangle? That is, are all three sides the same? Is it an isosceles triangle? That is, are two sides the same? (If your program has already determined that the triangle is equilateral, then it should NOT state that it is isosceles.) What is the area of the triangle? What is the perimeter of the triangle? Notes & Hints: You should break up your program into multiple (static) methods: classifyTriangle(...) perimeter(...) area(...) It may be easiest to deal with sorted values in classifyTriangle(...) Your program should be properly documented (use javadoc) Real numbers should be represented as doubles Java has a built in function called Math.sqrt() only use for loops, while loops, static methods, arrays, and basic integer functions

Explanation / Answer

import java.io.*;

import java.util.Scanner;

class TriangleStat

{

public static void main (String[] args)

{

//reading triangle edges using Scanner class

    float t1,t2,t3;

public static void classifytriangles()

{

//classifying triangles are isosceles triangle, equilateral triangle or normal triangle

if((t1=t2)&&(t2=t3))

System.out.println(" it is an isosceles triangle");

elseIf(t1=t2&&t3=t1||t2=t3&&t2=t1||t3=t1&&t3=t2)

System.out.println(" it is equilateral triangle");

else

System.out.println(" it is normal triangle");

}

public static void area()

{

   t4 = (t1 + t2 + t3 )/ 2 ;

double a = Math.sqrt(t4 * (t4 - t1) * (t4 - t2) * (t4 - t3));

System.out.println(" The area of triangle is"+a);

}

public static void perimeter()

{

//calculating perimeter of triangle

double p =t1+t2+t3;

System.out.println(" The perimeter of triangle is"+p);

}

Scanner scan = new Scanner( System.in );

    System.out.printin("Enter Triangle side1 length");

    t1= scan.nextFloat();

   System.out.println("Enter Triangle side2 length");

    t2= scan.nextFloat();

System.out.println("Enter Triangle side3 length");

    t3= scan.nextFloat();

//checking for the sum sum of any two edges

if((t1+t2<t3)&&(t2+t3<t1)&&(t3+t1<t2))

{

System.out.println("IT is a triangle");

TriangleStat o;

o.classifytriangles();

o.area();

o.perimeter();

}

else

System.out.println("IT is not a triangle");

}

}