Can someone point me in the right direction on how to get the triangle type to display. Below is a triangle class that is tested by another completely separate class. The main method of the test class executes the code you see below. What I'm trying to figure out is what I'm doing wrong in getting the triangle type to print. the integers typed in by the user print fine, but I keep getting "null" for the triangle type because I don't know how to call that part of the method correctly. I have triangleType as a String in the instance variables, is that correct? I also made triangleType part of the instance method, is that correct or should it be separate? Any help would be appreciated.
Code:
class triangle
{
//instance variables
int Side1;
int Side2;
int Side3;
String triangleType;
//constructor method for the three sides of the triangle
triangle(int s1, int s2, int s3)
{
Side1 = s1;
Side2 = s2;
Side3 = s3;
}
//instance method to determine the triangle type
public String triangleType()
{
if(Side1 == Side2 && Side2 == Side3)
{triangleType = "Equilateral";}
if(Side1 == Side2 && Side2 != Side3)
{triangleType = "Isoscelese";}
if(Side1 != Side2 && Side2 == Side3)
{triangleType = "Isoscelese";}
if(Side1 != Side2 && Side2 != Side3);
{triangleType = "Scalene";}
return triangleType();
}
//print out the values of the three sides and the triangle type
public void get_values()
{
System.out.println();
System.out.println("Side1" + "\t" + "Side2" + "\t" + "Side3" + "\t" + "Triangle Type");
System.out.println("===" + "\t" + "===" + "\t" + "===" + "\t" + "==========");
System.out.println( Side1 + "\t" + Side2 + "\t" + Side3 + "\t" + triangleType);
}
}
Comment