View the step-by-step solution to:

Right Triangle Class Write a RightTriangle class that has the following fields: legA: a double legB: a double The class should have the following...

Right Triangle Class 

 

Write a RightTriangle class that has the following fields:  legA: a double  legB: a double 

 

The class should have the following methods: 

 

 No-argument constructor. Sets fields to 0  Constructor. Accepts legs of the right triangle as arguments. Constructor throws Illegal Argument Exception when one or both legs are set to 0 or negative number(s) 

 setLegA(), setLegB() - mutator methods. Both methods throw Illegal Argument Exception when leg is set to 0 or negative number.  getLegA(),getLegB()-accessor methods.  getHypotenuse() - calculates and returns hypotenuse of the triangle.  GetArea() - calculates and returns area of the right triangle  getPerimeter()- calculates and returns perimeter of the triangle Call the source code files RightTriangle.java. 

 

Write a class with main() that uses your class.  Please do not collect input from the user. Instead, call ALL the methods of the class with the data you choose to make sure the methods work properly. In the comments explain why you decided to use these particular test cases.   Have try/catch blocks that handle Illegal Argument Exception. Make sure you write the call that invokes Illegal Argument Exception in main(). In addition, make sure to call class constructors and mutator methods with bad arguments to showcase exception throwing/catching in action. 

 

Call the source code files TriangleDemo.java. 

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question