How to tackle a homework prgram that reads three sides for a triangle and computes the area if the input is valid?

前端 未结 3 379
半阙折子戏
半阙折子戏 2021-01-29 07:06

Here is my task:

Create a class named MyTriangle that contains the following two methods:

/** Return true if the sum of any two sides is *         


        
3条回答
  •  故里飘歌
    2021-01-29 07:52

    So you write the following: if the input is valid, show error message. Otherwise (else) compute area. You should just swap your if and else parts! Your program never calls the area() method if you are calling it with points for a valid triangle. Moreover, you never call the isValid() method. You assign true to the variable, and then check it in the next line, but the method that actually checks it has never been called.

    ALSO you need side variables for isValid(), but you only compute them in the area() method. You should compute them right after you get the points.

提交回复
热议问题