154k views
0 votes
Write a public static method called createParty that has one parameter of type String[] called names containing the Pokemon names, followed by a parameter of type int[] called levels containing the Pokemon levels (where names[i] and levels[i] are the name and level of Pokemon i in the party). It should return the party as a ArrayList> as described above

2 Answers

3 votes

public static ArrayList<HashMap<String, Object>> createParty(String[] names,int[] levels)

{

ArrayList<HashMap<String, Object>> party = new ArrayList<HashMap<String,Object>>(6);

for(int i=0;i<6;i++) {

HashMap<String, Object> hm = new HashMap<String, Object>();

hm.put("Name", names[i]);

hm.put("Level", levels[i]);

party.add(hm);

}

return party;

}

Step-by-step explanation:

If the Sample data below is typed when the code above is executed

Beedrill Venasaur Charizard Blastoise Butterfree Weedle

88 84 84 84 80 82

The expected Output will be:

Beedrill 88

Venasaur 84

Charizard 84

Blastoise 84

Butterfree 80

Weedle 82

User Andreas Rehm
by
7.5k points
6 votes

Answer:

public static ArrayList<HashMap<String, Object>> createParty(String[] names,int[] levels)

{

ArrayList<HashMap<String, Object>> party = new ArrayList<HashMap<String,Object>>(6);

for(int i=0;i<6;i++) {

HashMap<String, Object> hm = new HashMap<String, Object>();

hm.put("Name", names[i]);

hm.put("Level", levels[i]);

party.add(hm);

}

return party;

}

Step-by-step explanation:

If the Sample data below is typed when the code above is executed

Beedrill Venasaur Charizard Blastoise Butterfree Weedle

88 84 84 84 80 82

The expected Output will be:

Beedrill 88

Venasaur 84

Charizard 84

Blastoise 84

Butterfree 80

Weedle 82

User Scatmoi
by
8.0k points

No related questions found

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.