Either use a switch statement or objects:
Switch statement:
public class Game {
private int level;
public void update() {
switch(level) {
case 1:
updateLevelOne();
break;
case 2:
updateLevelTwo();
break;
}
}
public static void setLevel(int lv) {
level = lv;
}
private updateLevelOne() {
.....
}
private updateLevelTwo() {
.....
}
}
Alternatively, make your levels objects:
public class Game {
private Level[] levels;
private int currentLevel;
public Game() {
levels = new Level[2]
levels[0] = new Level();
levels[1] = new Level();
currentLevel = 0;
}
public void update() {
levels[currentLevel].update();
}
public static void setLevel(int newLevel) {
currentLevel = newLevel;
}
}
public class Level {
public Level() {
}
public void update() {
}
}
Objects are preferred but you can go either way. You could also go with the reflection
package, but that's a worse idea that will be harder to understand.