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

Consider the following application, which uses a class called Triangle: public c

ID: 3697735 • Letter: C

Question

Consider the following application, which uses a class called Triangle:

public class TriangleTest {

   public static void main(String[] args) {

       // TODO Auto-generated method stub

       Scanner in = new Scanner(System.in);

       int firstSide = in.nextInt();

       int secondSide = in.nextInt();

       int thirdSide = in.nextInt();

      

       Triangle myTri = new Triangle(firstSide, secondSide, thirdSide);

       if(myTri.is_scalene())

           System.out.println("Is a scalene, no tow sides have the same length!");

       else

           System.out.println("Not a scalene, at least 2 sides have the same length!");

   }

}

For the Triangle class below, fill in the instance variables, constructor, and is_scalene(no two sides have the same length) method.

public class Triangle

{

//declare instance variables

//write the constructor

//write the method is_scalene method. A scalene triangle is one where no two sides have the same length. Study the above code to decide how to implement this method.

Explanation / Answer

public class Triangle
{
   public int first,second,third;
  
   public Triangle(int f,int s,int t)
   {
       first=f;
       second =s;
       third = t;
   }
   public boolean is_scalene()
   {
       boolean flag=true;
       if(first==second)
           flag = false;
       if(third==second)
           flag = false;
       if(first==third)
           flag = false;
       return flag;
   }
}

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