Question: public class Triangle { private double side1, side2, side3; public Triangle(double side1, double side2, double side3) { this.side1 = side1; this.side2 = side2; this.side3 =

public class Triangle { private double side1, side2, side3; public Triangle(double side1, double side2, double side3) { this.side1 = side1; this.side2 = side2; this.side3 = side3; } public double getSide1() { return side1; } public void setSide1(double side1) { this.side1 = side1; } public double getSide2() { return side2; } public void setSide2(double side2) { this.side2 = side2; } public double getSide3() { return side3; } public void setSide3(double side3) { this.side3 = side3; } @Override public String toString() { return "Triangle [getSide1()=" + getSide1() + ", getSide2()=" + getSide2() + ", getSide3()=" + getSide3() + "]"; } }
Question 2: Code of Triangle class is given below. Triangle class is defined with three sides. In a triangle, the sum of any two sides is greater than the other side. The Triangle class must adhere to this rule. Create the IllegalTriangleException class, and modify the constructor of Triangle class to throw an IllegalTriangleException object if a triangle is created with sides that violate the rule, as follows: //Constructor public Triangle(double side 1, double side 2, double side 3) throws IllegalTriangleException { //Implement it } The constructor should not handle the exception itself. Rather, it should propagate the exception to the method in which the constructor is called (i.e. the triangle object is created)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
