Hey guys I need help defining a method in Java for a project

Hey guys, I need help defining a method in Java for a project. The exact description for the method is:

• This method returns an array of Strings containing the names of every Pokemon stored in the Pokedex. The Pokedex class has a field that is an array of Pokemon objects. This method will look at each Pokemon stored in the Pokedex object’s Pokemon array, access the name of the species, and save it into an Array of Strings. The String[]output should be a list containing the names of all Pokemon species currently saved in the Pokedex, with no empty indexes. For example, if your Pokedex holds 20 Pokemon and you have only stored 10, your String[] returned should have a length of 10, not 20. If the Pokedex is currently empty, return null.

Solution


public class Pokedex {
Pokemon[] pokemons;
String[] getPokemon()
{
String[] temp=new String[200];

int len=pokemons.length;

if(len==0)

{

System.out.println(\"Pokedex array is empty\");

}

else{
for(int i=0;i<len;i++)
{
temp[i]=pokemons[i].toString();
}
return temp;

}
}

public static void main(String[] args) {
Pokedex ob=new Pokedex();
String result[]=ob.getPokemon();
for(int j=0;j<result.length;j++)
{
System.out.println(result[j]);
}
}
}

Hey guys, I need help defining a method in Java for a project. The exact description for the method is: • This method returns an array of Strings containing the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site