I'm trying to figure out how to randomize the object selected as a parameter in a method. So I created two Pokemon classes below (rattata and pidgey)
class WildPokemon {
private static int randomHealth(int min, int max) {
int range = (max - min) + 1;
return (int)(Math.random() * range) + min;
}
private static int randomAttack(int min, int max) {
int range = (max - min) + 1;
return (int)(Math.random() * range) + min;
}
private static int randomSpeed(int min, int max) {
int range = (max - min) + 1;
return (int)(Math.random() * range) + min;
}
static Pokemon rattata = new Pokemon("Rattata",randomHealth(15,20),randomAttack(2,5),randomSpeed(2,6));
static Pokemon pidgey = new Pokemon("Pidgey",randomHealth(10,17),randomAttack(3,4),randomSpeed(3,5));
}
Below I am able to call rattata in the method Pokemon.battle() and it functions as expected. Is there a way I could randomize my second parameter to where it could be either rattata or pidgey selected at random?
public class PokemonTester{
public static void main(String[] args){
Pokemon.battle(starter, WildPokemon.rattata);
}
}