#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0

    Help with a method


    My teacher assigned us to make a quadratic class as extra credit and I am having a problem with this particular method. It says I am missing a return statement cause all my return statements are in If statements. I just don't know what I would return if none of these If statements are true.

    public int vertexQuad(){
    if(calcVertX()>0 && calcVertY()>0)
    return 1;

    if(calcVertX()<0 && calcVertY()>0)
    return 2;

    if(calcVertX()<0 && calcVertY()<0)
    return 3;

    if(calcVertX()>0 && calcVertY()<0)
    return 4;

    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    74
    Rep Power
    19
    You can have return the method any value you want, except offcourse the value you are already returning because then you dont know why the value returned.
    Two solutions:

    return -1 at the end of the function, and test whenever you use this function on -1 .

    Make an enum for this rather than integer

IMN logo majestic logo threadwatch logo seochat tools logo