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;
}
}