import java.util.ArrayList; //import java.util.Iterator; /** * A PokemonSpecies entry in the Pokedex. Maintains the number of candies associated * with the Pokemon species as well as the Trainer\'s inventory of Pokemon of this * species. */ public class PokemonSpecies { private int pokedexNumber; private String speciesName; private int candies; /** * Maintains the list of Pokemon of this species in the Trainer\'s inventory. */ private ArrayList caughtPokemon; /** * Constructor suitable for a newly encountered Pokemon species during the course of the * game and for loading species data from a save file. * */ public PokemonSpecies(int pokedexNumber, String speciesName, int candies) { this.pokedexNumber = pokedexNumber; this.speciesName = speciesName; this.candies = candies; // construct caughtPokemon caughtPokemon = new ArrayList(); } /** * Getter methods */ public Integer getPokedexNumber() { return pokedexNumber; } public String getSpeciesName() { return speciesName; } public int getCandies() { return candies; } /** * Add a newly caught Pokemon to the player\'s inventory and * increase the number of candies for this PokemonSpecies * * @param pokemon the newly caught Pokemon */ public void addNewPokemon(Pokemon pokemon) { caughtPokemon.add(pokemon); this.addNewPokemonCandies(); } /** * Helper function to load Pokemon from a save file into the player\'s inventory for this * Pokemon Species */ public void loadPokemon(Pokemon pokemon) { caughtPokemon.add(pokemon); } /** * Find a Pokemon of the given combatPower in the player\'s inventory for this species. * */ public Pokemon findPokemon(int cp) throws PokedexException { for(int i = 0; i < caughtPokemon.size(); i++){ Pokemon mon = caughtPokemon.get(i); if(mon.getCombatPower() == cp){ return mon; } } throw new PokedexException(Config.POKEMON_NOT_FOUND); } /** * Transfer a Pokemon with the provided combatPower from the player\'s inventory * to the Professor. This removes the Pokemon from the player\'s inventory and * also increases the number of candies the player has associated with this * PokemonSpecies. */ public Pokemon transferPokemon(int cp) throws PokedexException { for(int i = 0; i < caughtPokemon.size(); i++){ if(caughtPokemon.get(i).getCombatPower() == cp){ Pokemon mon = caughtPokemon.remove(i); this.addTransferCandies(); return mon; } } throw new PokedexException(Config.POKEMON_NOT_FOUND); } /** * Check if the player has any Pokemon of this species */ public boolean isEmpty() { return caughtPokemon.isEmpty(); } /** * Increment candies when a new pokemon is caught */ private void addNewPokemonCandies() { this.candies += PokemonGO.NEW_POKEMON_CANDIES; } /** * Increment candies when a pokemon is transferred to the professor */ private void addTransferCandies() { this.candies += PokemonGO.TRANSFER_POKEMON_CANDIES; } /** * Prepare a listing of all the Pokemon of this species that are currently in the * player\'s inventory. * */ public String caughtPokemonToString() { String pokemonStr = \"\"; .