In: Computer Science
Create a custom Exception named IllegalTriangleSideException. Create a class named Triangle. The Triangle class should contain 3 double variables containing the length of each of the triangles three sides. Create a constructor with three parameters to initialize the three sides of the triangle. Add an additional method named checkSides with method header - *boolean checkSides() throws IllegalTriangleSideException *. Write code so that checkSides makes sure that the three sides of the triangle meet the proper criteria for a triangle. It will return true if and only if the sum of side1+ side2 is greater than side3 AND the sum side2+side3 is greater than side1 AND the sum of side1+ side3 is greater than side2. If any of those three conditions is not met, the method will create and throw an IllegalTriangleSideException. Add a main method to create and check two to three different triangles.
class IllegalTriangleSideException extends
RuntimeException{
public IllegalTriangleSideException(String m) {
super(m);
}
}
public class Triangle {
private double side1;
private double side2;
private double side3;
public Triangle(double aSide1, double aSide2, double
aSide3) {
super();
side1 = aSide1;
side2 = aSide2;
side3 = aSide3;
}
boolean checkSides() throws
IllegalTriangleSideException{
if ((side1 + side2) >
side3)
throw new IllegalTriangleSideException("Invalid
Sides");
else
return
true;
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME