import javax.swing.*;
public class Triangle {
public static void main(String[] args) {
int side1 = getSides();
int side2 = getSides();
int side3 = getSides();
boolean rightTriangle = isRight( side1, side2, side3 );
boolean scaleneTriangle = isScalene( side1, side2, side3 );
boolean isoscelesTriangle = isIsosceles( side1, side2, side3 );
boolean equilateralTriangle = isEquilateral( side1, side2, side3 );
double areaOfT = findArea( side1, side2, side3 );
if ( rightTriangle == true ) {
JOptionPane.showMessageDialog( null, "This is a Right Traingle");
}
if ( scaleneTriangle == true ) {
JOptionPane.showMessageDialog( null, "This is a Scalene Traingle");
}
if ( isoscelesTriangle == true ) {
JOptionPane.showMessageDialog( null, "This is an Isosceles Traingle");
}
if ( equilateralTriangle == true ) {
JOptionPane.showMessageDialog( null, "This is an Equilateral Traingle");
}
JOptionPane.showMessageDialog(null, "Side 1 is: " + side1 + "\nSide 2 is: " + side2 + "\nSide 3 is: " + side3 + "\nThe area of the traingle is: " + areaOfT );
} // ends main method
public static int getSides() {
int testside = Integer.parseInt( JOptionPane.showInputDialog("Enter Side: "));
while ( testside < 0 ) {
testside = Integer.parseInt( JOptionPane.showInputDialog("INVALID INPUT MUST BE GREATER THAN 0!\n\nEnter another number: "));
} // ends while loop
return testside;
} // ends getInput method
public static boolean isRight( int side1, int side2, int side3 ) {
double sqrSide1 = Math.pow( side1,2 );
double sqrSide2 = Math.pow( side2,2 );
double sqrSide3 = Math.pow( side3,2 );
double sqr12 = Math.pow( side1,2 ) + Math.pow( side2,2 );
double sqr13 = Math.pow( side1,2 ) + Math.pow( side3,2 );
double sqr23 = Math.pow( side2,2 ) + Math.pow( side3,2 );
if ( sqr12 == sqrSide3 || sqr13 == sqrSide2 || sqr23 == sqrSide1 ) {
return true;
} // ends true if
else {
return false;
} // ends false else
} // ends isRight method
public static boolean isScalene( int side1, int side2, int side3 ) {
if ( side1 != side2 && side1 != side3 && side2 != side3 ) {
return true;
} // ends true if
else {
return false;
} // ends false else
} // ends isScalene method
public static boolean isIsosceles( int side1, int side2, int side3 ) {
if ( side1 == side2 || side1 == side3 || side2 == side3 ) {
return true;
} // ends true if
else {
return false;
} // ends false else
} // ends isIsosceles method
public static boolean isEquilateral( int side1, int side2, int side3 ) {
if ( side1 == side2 && side1 == side3 && side2 == side3 ) {
return true;
} // ends true if
else {
return false;
} // ends false else
} // ends isEquilateral method
public static double findArea( int side1, int side2, int side3 ) {
double x = .5 * ( side1 + side2 + side3 );
double area = Math.sqrt( x * ( x - side1 ) * ( x - side2 ) * ( x - side3 ) );
return area;
} // ends findArea method
} // ends public class Triangle