Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Triangle class

TobuwayTobuway Member Posts: 12
I had an assignment recently were I created a class called Triangle that would take three double numbers as the sides of the triangle. One of the methods would calculate and return the area of the triangle using Heron's formula, I also had to make sure it would return -1.0 if the side entered would not create a triangle, my teacher said that I failed on this section and I can't figure out why. Here is the area method:

public double getArea(){
double s = 0.5 * (sideA + sideB +sideC);
if(Math.sqrt(s*(s-sideA)*(s-sideB)*(s-sideC)) >= 0.0)
return Math.sqrt(s*(s-sideA)*(s-sideB)*(s-sideC));
return -1.0;

What did I do wrong?


  • TobuwayTobuway Member Posts: 12
    I forgot to mention that I added the return -1.0 if the calculation was not greater than zero beacuse my testing returned Nan(Not a number) and that was the best way I could figure to handle the problem.
Sign In or Register to comment.