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

In java language 3 Testing a Property of a Triangle On the next page, write a me

ID: 3600074 • Letter: I

Question

In java language

3 Testing a Property of a Triangle On the next page, write a method triangleTest that receives three double values a b and c as its formal parameters, which represent the lengths of the three sides of a possible "triangle" in an arbitrary order, asserts whether or not the three values represent a valid triangle (the program does not state why), and, if they do, asserts whether or triangle. Note: . The three values represent a valid triangle if and only if (a) all the lengths are strictly positive and (b) the length of each side is strictly smaller than the sum of the lengths of the other two sides. The three values represent an isosceles triangle if one value is equal to one of the other two. Consider the following four examples ·The length values 6.3, 2.0, and 3.0 cannot represent a valid triangle since 6.3 >= 2.0 + 3.0. The length values 17.5, -4.5, and 2.0 cannot represent a valid triangle since one value is negative. The length values 3.5, 3.0, and 4.5 represent a valid triangle, but not an isosceles triangle. The length values 7.5, 10.0, and 7.5 represent a valid triangle and an isosceles triangle. Given the four sets of parameters, the assertions that the method makes are respectively as follows: An invalid triangle An invalid triangle A valid triangle Not an isosceles triangle A valid triangle An isosceles triangle Note that the screen output is identical between the first and the second, since the program does not explain why the three values fail to represent a valid triangle.

Explanation / Answer

public class Triangle_Test {

public static void main (String argc[]){

System.out.println("Case 1: Sides are 6.3 , 2.0 and 3.0");

triangleTest(6.3,2.0,3.0);

System.out.println("Case 2: Sides are 17.5 , -4.5 and 2.0");

triangleTest(17.5,-4.5,2.0);

System.out.println("Case 3: Sides are 3.5 , 3.0 and 4.5");

triangleTest(3.5,3.0,4.5);

System.out.println("Case 4: Sides are 7.5 , 10.0 and 7.5");

triangleTest(7.5,10.0,7.5);

}

public static void triangleTest(double a, double b, double c){

boolean validTriangle = false;

if(a>=0 && b>=0 && c>=0){

if(a<(b+c) && b<(a+c) && c<(a+b)){

validTriangle = true;  

}

}

if(validTriangle){

System.out.println("A valid triangle.");

if(a==b || b==c || c==a){

System.out.println("An isosceles triangle.");

}

else{

System.out.println("Not an isosceles triangle.");

}

}

else{

System.out.println("An invalid triangle.");

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote