mercredi 30 novembre 2016

error with method not returning int - compiler error

when i try to compile its throwing error "method must return an int" any help is much obliged. also, will the rand variable reset to a different random value every time the method is called? thankyouthankyouthankyou

public static int giveType(int oSquareType, int x, int y){
int rand = (int)(Math.random()*100+1);
if(oSquareType == 1){
  if(rand>=0 || rand <= 80){
    return 1;
  }else if(rand>=81 || rand <= 85){
    return 2;
  }else if(rand>=86 || rand <=90 ){
    return 3;
  }else if(rand>=91 || rand <= 95){
    return 4;
  }else if(rand>=96 || rand <= 100){
    return 5;
    }
  }else if(oSquareType == 2){
    if(rand>=0 || rand <= 5){
      return 1;
    }else if(rand>=6 || rand <= 80){
      return 2;
    }else if(rand>=81 || rand <= 90){
      return 3;
    }else if(rand>=91 || rand <= 100){
      return 5;
    }

    }else if(oSquareType == 3){
      if(rand>=0 || rand <= 10){
        return 1;
      }else if(rand>=11 || rand <= 15){
        return 2;
      }else if(rand>=16 || rand <= 90){
        return 3;
      }else if(rand>=91 || rand <= 95){
        return 4;
      }else if(rand>=96 || rand <= 100){
        return 5;
        }


      }else if(oSquareType == 4){
        if(rand>=0 || rand <= 10){
          return 1;
        }else if(rand>=11 || rand <= 20){
          return 3;
        }else if(rand>=21 || rand <= 95){
          return 4;
        }else if(rand>=96 || rand <= 100){
          return 5;
          }


        }else if(oSquareType == 5){
          if(rand>=0 || rand <= 10){
            return 1;
          }else if(rand>=11 || rand <= 20){
            return 2;
          }else if(rand>=21 || rand <= 30){
            return 3;
          }else if(rand>=31 || rand <= 40){
            return 4;
          }else if(rand>=41 || rand <= 100){
            return 5;
            }
          }//end if block
        }//end method

Aucun commentaire:

Enregistrer un commentaire