/**
* This class makes a virtual triangle
*
* This code is licensed under the GNU GPLv3, you can find it here https://www.gnu.org/licenses/gpl-3.0.en.html
*
* @author (Nicholas Tsimerekis)
* @version (Version 1)
*/
public class Triangle
{
// instance variables - replace the example below with your own
private int hypotenuse;
private int longLeg;
private int shortLeg;
public Triangle(int side1, int side2, int side3)
{
hypotenuse = Math.max(side3, Math.max(side1, side2));
if (side1 == hypotenuse){
longLeg = Math.max(side2, side3);
shortLeg = Math.min(side2, side3);
}//end if
if (side2 == hypotenuse){
longLeg = Math.max(side1, side3);
shortLeg = Math.min(side1, side3);
}//end if
if (side3 == hypotenuse){
longLeg = Math.max(side1, side2);
shortLeg = Math.min(side1, side2);
}//end if
}
public String getAngleType()
{
if(longLeg + shortLeg > hypotenuse) /*If this is a triangle */
{
//If - Else for code effeciency.
if (Math.pow(shortLeg,2) + Math.pow(longLeg,2) == Math.pow(hypotenuse,2) )
return "right";
else
if (Math.pow(shortLeg,2) + Math.pow(longLeg,2) < Math.pow(hypotenuse,2) )
return "obtuse";
else
if (Math.pow(shortLeg,2) + Math.pow(longLeg,2) > Math.pow(hypotenuse,2) )
return "acute";
else
return "not a real triangle";
}//end if
else /*If this is not a triangle*/
{
return "not a triangle";
}//end else
}
public int getShortLeg()
{
return shortLeg;
}
public int getLongLeg()
{
return longLeg;
}
public int getHypotenuse()
{
return hypotenuse;
}
}