The triangle inequality principle states that the sum of the lengths of any two sides of a triangle always exceeds the length of the third side.
Pythagoras' theorem states that the square of the hypotenuse (the side opposite the right angle) is equal to the sum of the squares of the other two sides
Write a java class Triangle that has the three sides of the triangle as attributes. It also has the following methods:
isItTriangle(): boolean. Returns true if the three sides accurately represents a triangle. (Any side cannot exceed the sum of both other sides). Otherwise returns false.
isItRight(): boolean. Returns true if the all three sides represent a triangle and it is a right angle tiangle satisfying Pythagoras theorm. otherwise returns false.
longest(): double. Returns the longest side.
Triangle |
+ side1 : double
+ side2 : double
+ side3 : double
|
+ isItTriangle(): boolean
+ isItRight(): boolean
+ longets():double
|
Write a class testTriangle that:
Declare a Triangle object t and prompts the user to enter the lengths of three sides of a triangle.
displays a message indicating whether the lengths correctly represent a triangle, and if it is, displays a message indicating whether the triangle is a right triangle.
Sample Run 1
Enter the three sides 4 6 8
It is a triangle
Not a Right angle triangle
The longest side is 8.0
Sample Run 2
Enter the three sides 1 2 8
It is not a triangle