// // triangle // // Author : K.J. Chan // Date : Novermber 2008 // Language : Java // Description: triangle class // class triangle { ////////////////////////////////////////// // Declarations ////////////////////////////////////////// private double S1 ; private double S2 ; private double S3 ; final int NOT_A_TRIANGLE = 0 ; final int EQUILATERAL = 1 ; final int ISOSCELES = 2 ; final int RIGHT_ANGLE = 3 ; final int SCALENE = 4 ; ////////////////////////////////////////// // Constructor ////////////////////////////////////////// public triangle( double side1, double side2, double side3 ) { S1 = side1 ; S2 = side2 ; S3 = side3 ; } ////////////////////////////////////////// // method: what_triangle_type // work out what sort of triangle we have ////////////////////////////////////////// public int get_triangletype() { if ( S1 >= S2+S3 ) return( NOT_A_TRIANGLE ) ; else if ( S2 >= S1+S3 ) return( NOT_A_TRIANGLE ) ; else if ( S3 >= S1+S2 ) return( NOT_A_TRIANGLE ) ; else if ( (S1 == S2) && (S2 == S3) ) return( EQUILATERAL ) ; else if ( S1 == S2 ) return( ISOSCELES ) ; else if ( S1 == S3 ) return( ISOSCELES ) ; else if ( S2 == S3 ) return( ISOSCELES ) ; else if ( S1*S1 == S2*S2 + S3*S3 ) return( RIGHT_ANGLE ) ; else if ( S2*S2 == S1*S1 + S3*S3 ) return( RIGHT_ANGLE ) ; else if ( S3*S3 == S1*S1 + S2*S2 ) return( RIGHT_ANGLE ) ; else return( SCALENE ) ; } }