At the point of return b, b should be initialised. It will be initialised in case a is 4, 5 and 6; but what if a is 28? You're saying it shouldn't be able to happen, but things that shouldn't happen happen all the time, and the compiler likes to have all its bases covered.
Either initialise b at top to cover all cases, or make sure to assign it in each branch of the switch (including default).
Another possibility (which I actually like best) is to make sure your code can not reach return in the default case; you can throw an exception there (maybe IllegalStateException, "there is something wrong with the code!") and the compiler will then know it can't reach return through default, and not complain about b being unassigned. Your code should not happily proceed when your assumptions are violated, so this fits well.
public static int setMapTile() {
int a = getArmadaLength(); // 4 to 6
int b;
switch (a) {
case 4:
System.out.println(" recommended MapSize : 10 x 10");
b = setSize();// method for bigger map, return int
break;
case 5:
System.out.println(" recommended MapSize : 11 x 11");
b = setSize();// method for bigger map, return int
break;
case 6:
System.out.println(" recommended MapSize : 12 x 12");
b = setSize();// method for bigger map, return int
break;
default:
throw new IllegalStateException("Armada length is " + a + "?!?");
break;
}
return b;
}
In this specific case, actually, you can even factor out the b outside of the switch and completely avoid the problem. Also, that last break is redundant.
public static int setMapTile() {
int a = getArmadaLength(); // 4 to 6
switch (a) {
case 4:
System.out.println(" recommended MapSize : 10 x 10");
break;
case 5:
System.out.println(" recommended MapSize : 11 x 11");
break;
case 6:
System.out.println(" recommended MapSize : 12 x 12");
break;
default:
throw new IllegalStateException("Armada length is " + a + "?!?");
}
return setSize();
}