Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Define a Triangle class with three private double instance variables, each of which represents the length of one side of the triangle, and a single

Define a Triangle class with three private double instance variables, each of which represents the length of one side of the triangle, and a single three-argument constructor. For any triangle, the sum of any two sides must be greater than the remaining side. Your Triangle class must adhere to this rule. Define an IllegalTriangleException class (an empty subclass of Exception), and define Triangles constructor to raise an IllegalTriangleException if the user attempts to create a Triangle whose sides violate the rule above. Your Triangle constructor header should resemble the following: /** Construct a triangle with the specified sides */ public Triangle(double side1, double side2, double side3) throws IllegalTriangleException { // Implement your constructor } Finally, define a main() method (inside Triangle or in a separate driver class) that prompts the user to enter a length for each side, and then creates a new Triangle with those values. If the user enters an invalid set of values (meaning that the Triangle constructor generates an exception), your program should use exception- handling to print an appropriate message instead of simply crashing.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Question List of 1 0

Answered: 1 week ago