posted 1 year ago
I need to implement methods of class Triangle:
constructor, which has three points as parameters.
Make sure that these points refer to vertices of the triangle.
Ensure that the created triangle exists and it is not degenerative.
If it is, use throw new IllegalArgumentException() to raise an error.
double area()
Return the area of the triangle.
Point centroid()
Return the centroid of the triangle.
Class Point is already there.
Examples
You may use Main class to try your code. There are some examples below.
Sample code:
Sample code:
Sample code:
This is the Point class:
This is the Triangle class:
This is the Main class:
I don;t know how to implement this statement: "Ensure that the created triangle exists and it is not degenerative.
If it is, use throw new IllegalArgumentException() to raise an error."
What I understand is that if triangle is degenerative I must throw new IllegalArgumentException().
I googled about that and I found that if a, b, and c are the lengths of the three sides of a triangle, then a + b > c, a + c > b, b + c > a. If any one of these inequalities is not true, then we get a degenerate triangle.
I tried to put in constructor like this:
I get an error: " Operator '+' cannot be applied to 'com.epam.rd.autotasks.triangle.Point', 'com.epam.rd.autotasks.triangle.Point' "
Do you know why doesn't let me to continue further?