Question: Design and implement a class named Triangle. The class contains: Three double data fields named side 1 , side 2 , and side 3 with

Design and implement a class named Triangle. The class contains:
Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides (lengths) of the triangle. Sides are in no particular order.
The accessor (getters) methods for all three data fields.
Mutator (setters) methods for all three fields. Remember you can't except a zero or negative numbers as sides.
A no-arg constructor that creates a default triangle.
A constructor that creates a triangle with the specified side1, side2, and side3.
A method named isValid() that returns true or false if the sides form a valid triangle. Remember the sides are not in any particular order and that a triangle is not valid if you have a side that is longer than the sum of the other two. Think about it. Can you have a triangle if the sides are 1,100,2?
A method named getArea() that returns the area of this triangle. Use Heron's Formula to compute the area. If the triangle is not valid, return -1.
A method named getPerimeter() that returns the perimeter of this triangle. If the the triangle is not valid, return -1.
A method named toString() that returns a string description for the triangle. This method should return something like Triangle: side1=10, side2=5, side3=7
Make sure that when bad triangle sides are used to construct the triangle that the appropriate error message(s) are given. If you attempt to get the triangle's area and perimeter, output the appropriate error messages if the triangle is not valid

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!