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 side side and side with default values 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 noarg constructor that creates a default triangle.
A constructor that creates a triangle with the specified side side and side
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
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
A method named getPerimeter that returns the perimeter of this triangle. If the the triangle is not valid, return
A method named toString that returns a string description for the triangle. This method should return something like Triangle: side side side
Make sure that when bad triangle sides are used to construct the triangle that the appropriate error messages 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
