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

8. write the code for the client method isscalar, one that receives a reference

ID: 3837566 • Letter: 8

Question

8. write the code for the client method isscalar, one that receives a reference a construc Triangle and that returns the value true is and if the values if the referenced sidel side2, and side3 represent the instance indicate the fact that the values of sides are equal). For required conditions of a scalar triangle (none of the three value null triangles those valid triangles that are not les, the method returns the false. (Hint: Use the code of questions 6 and 7 to make this a very easy method to code!) In the run of the client application, code that calls this method five times is given within the statements of the testisScalar method.

Explanation / Answer

// method to check if given triangle t is scaler or not
public boolean isScaler(Triangle t){
// if triangle is null return false
if(t == null){
return false;
}
// else get the sides of triangle
double a = t.getSide(1);
double b = t.getSide(2);
double c = t.getSide(3);
// check if this is a valid triangle
boolean case1 = (a + b) > c;
boolean case2 = (b + c) > a;
boolean case3 = (c + a) > b;
// if it is a valid triangle i.e, sum of any two side is greater then third then
if(case1 && case2 && case3){
// check if all sides are different
boolean s1 = a != b;
boolean s2 = b != c;
boolean s3 = c != a;
// if all side is different return true
if(s1 && s2 && s3){
return true;
}
}
// else return false
return false;
}

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