Question
Java programming (IllegalTriangleException) Programming Exercise 11.1 defined the Triangle class with three sides. In a triangle, the sum of any two sides is greater than
Java programming
(IllegalTriangleException) Programming Exercise 11.1 defined the Triangle class 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 the Triangle class to throw an IllegalTriangleException object if a triangle is created with sides that violate the rule, as follows: /** Construct a triangle with the specified sides */ public Triangle(double side1, double side2, double side3) throws IllegalTriangleException {
-
A test program is given below. Please complete the whole program. public class Test { public static void main(String[] args) { try { Triangle t1 = new Triangle (1.5, 2, 3); System.out.println("Perimeter for t1: " + t1.getPerimeter()); System.out.println("Area for t1: " + t1.getArea()); Triangle t2 = new Triangle (1, 2, 3); System.out.println("Perimeter for t2: " + t2.getPerimeter()); System.out.println("Area for t2: " + t2.getArea()); } catch (IllegalTriangleException ex) { System.out.println("Illegal triangle"); System.out.println("Side1: " + ex.getSide1()); System.out.println("Side2: " + ex.getSide2()); System.out.println("Side3: " + ex.getSide3()); } } } class IllegalTriangleException extends Exception { // Implement it } class Triangle extends GeometricObject { double side1, side2, side3; //Modify the constructor of the Triangle Class public Triangle (double side1, double side2, double side3) throws IllegalTriangleException { // Implement it } //In order to make the Test class run successfully, you should add the definitions of the left methods in the class Triangle.
-
Please submit the output with image
// Implement it }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started