Stack Exchange
Error: missing return statement (once more)
  public static int salariDepart1( int duradaPeriode, int horesEfectives, float preuHora, int bonificHoresExtres) {
    int salary;

    if(duradaPeriode<0||horesEfectives<0||preuHora<0||bonificHoresExtres<0){
      return (int) -1;
    }

    else if(horesEfectives<(duradaPeriode-(duradaPeriode*0.75))){
      if(preuHora<6){
        salary =  (int) (preuHora * horesEfectives);
        return (int) Math.round(salary);
      }

      else{
        salary = (int) (horesEfectives * (preuHora-(preuHora*0.10)));
        return (int) Math.round(salary);
      }
    }


    else if(horesEfectives>(duradaPeriode+(duradaPeriode*0.20))){
      bonificHoresExtres = (int) (preuHora+(preuHora*0.03));
      if(bonificHoresExtres>200){
        return (int) -2; 
      }

      else if(bonificHoresExtres<200){
        salary = (int) (horesEfectives * (preuHora+(preuHora*0.03)));
        return (int) Math.round(salary);
      }

      else{
        salary  =  (int) (horesEfectives * preuHora);
        return (int) Math.round(salary);
      } 
    }
  }

  public static void main(String[] args){

    System.out.println(salariDepart1(200,120,8,5));
    System.out.println(salariDepart1(190,100,7,10));
    System.out.println(salariDepart1(180,90,7,20));

  }
}

This error keeps popping up, and I dont know why. Help is appreciated. :)

You need a return statement which isn't inside conditional logic. Assume all your ifs and else ifs fail. There is no return statement for your compiler to see a way to exit the method

There is no else path for
else if(horesEfectives>(duradaPeriode+(duradaPeriode*0.20))){

So if that condition is not satisfied the compiler needs a return statement, which is missing.
Generally one should avoid to have many return statements, instead you better should introduce a returnValue variable which you inizialize  at the beginning. This improves the abiliyt to debug your code.
int retVal = -1;

and assign the retVal in each of the conditions,
eg:
..
 retVal =  Math.round(salary);

..
 finally return the value as last line
   return retVal;


The reason gets clearer if you indent the code consistently and clearly:
public static int salariDepart1(int duradaPeriode, int horesEfectives, float preuHora, int bonificHoresExtres) {
    int salary;

    if (duradaPeriode < 0 || horesEfectives < 0 || preuHora < 0 || bonificHoresExtres < 0) {
        return (int) - 1;
    } else if (horesEfectives < (duradaPeriode - (duradaPeriode * 0.75))) {
        if (preuHora < 6) {
            salary = (int)(preuHora * horesEfectives);
            return (int) Math.round(salary);
        } else {
            salary = (int)(horesEfectives * (preuHora - (preuHora * 0.10)));
            return (int) Math.round(salary);
        }
    } else if (horesEfectives > (duradaPeriode + (duradaPeriode * 0.20))) {
        bonificHoresExtres = (int)(preuHora + (preuHora * 0.03));
        if (bonificHoresExtres > 200) {
            return (int) - 2;
        } else if (bonificHoresExtres < 200) {
            salary = (int)(horesEfectives * (preuHora + (preuHora * 0.03)));
            return (int) Math.round(salary);
        } else {
            salary = (int)(horesEfectives * preuHora);
            return (int) Math.round(salary);
        }
    }
}

What if duradaPeriode is >= 0 but neither horesEfectives < (duradaPeriode - (duradaPeriode * 0.75)) nor horesEfectives > (duradaPeriode + (duradaPeriode * 0.20)) is true? That's the path where the code doesn't return a value. So there's a path through the code that doesn't have a return.
Even if the conditions were all mutually-exclusive, the compiler can't always know that they are If they really are (which I don't think is the case above), make the final else if just an else. If they aren't, well, that's your problem, you need a returnin that case.

Set a default value that is returned when none of the conditional return statements are used.
So adding 

return -1

for example at the end of the function will solve this

Not all code paths in your logic will encounter a return statement.  Hence, you're missing one.
Your structure looks essentially like this:
if (something) {
  if (something) {
    return;
  } else {
    return;
  }
} else if (something) {
  if (something) {
    return;
  } else {
    return;
  }
}

Your "inner" conditionals are fine, but look at the "outer" one:
if (something) {
  // every path in here returns
} else if (something) {
  // and every path in here returns
}

What if neither of the "outer" conditions is true?  No return statement is ever encountered.
Add an else to the "outer" conditional with a return or add a return after the entire conditional block.  Every possible logical path through the method must return something.
