1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
k0ka [10]
4 years ago
10

Imagine you're developing a Pokemon game, and you need to implement the battle party mechanic. Recall that the player's party ca

n hold at most 6 Pokemon. To simplify things, you want to implement it as an ArrayList containing 6 elements (1 for each Pokemon in the party), and to simplify things even further, you decide to avoid making a custom Pokemon class. Instead, you choose to represent each Pokemon as a HashMap containing two keys: "Name" and "Level". The value associated with the key "Name" will be a String denoting the Pokemon's name, and the value associated with the key "Level" will be an Integer denoting the Pokemon's level. TASK: 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 HINT: Each Pokemon would be its own HashMap, and each of these HashMaps has exactly two keys, both of which are Strings: "Name" and "Level" Sample Input: Pikachu Venusaur Charizard Blastoise Lapras Snorlax 88 84 84 84 80 82 Sample Output: Pikachu 88 Venusaur 84 Charizard 84 Blastoise 84 Lapras 80 Snorlax 82 Write a program, test using stdin → stdout

Computers and Technology
1 answer:
valina [46]4 years ago
4 0

Answer:

Complete code is given below and output is also attached.

Explanation:

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Iterator;

import java.util.Map;

import java.util.Set;

public class Test {

  public static void main(String[] args) {

      String [] names = {"Pikachu", "Venuasur", "Charizard", "Blastoise", "Lapras", "Sonarlax"};

      int[] levels = {88, 84, 84, 84, 80, 82};

     

      ArrayList<HashMap<String, Integer>> party = createParty(names, levels);

     

      //looping through the list

      for(HashMap<String, Integer> i: party) {

         

          Set set = i.entrySet();

          Iterator itr = set.iterator();

          //showing output

          while(itr.hasNext()) {

              Map.Entry mentry = (Map.Entry)itr.next();

              System.out.println(mentry.getKey()+" "+mentry.getValue());

          }

      }

  }

  private static ArrayList<HashMap<String, Integer>> createParty(String[] names, int[] levels) {

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

     

      for(int i=0; i<names.length; i++) {

          //creating new hashmap

          HashMap<String, Integer> pokemon = new HashMap<>();

          pokemon.put(names[i], levels[i]);//adding pokemon

          party.add(pokemon);//adding it to the list

      }

     

      return party;

  }

}

You might be interested in
Write an if statement that assigns 0.2 to commission if sales is greater than or equal to 10000.
7nadin3 [17]
If (sales >= 10000)
commission = 0.2;
8 0
2 years ago
WHY DO YOU DElete EVERY QUESTIONS THAT IS ASKED! Im a freaking guy, yes and i wont followers for my channel so leave me alone!
skelet666 [1.2K]

Answer:

okie

Explanation:

8 0
3 years ago
Read 2 more answers
To save a file so that it can be opened on most computers, select the _____ option.
romanna [79]
Save it on the cloud.
6 0
4 years ago
Read 2 more answers
Question 15 of 25
GaryK [48]
It gains purchasing power. Less money in circulation = more value.
5 0
3 years ago
What device connects a lan's switch to the next network? qizzlets?
laila [671]
I think you can call it to a Network Switch, but LAN is always used device network: Hubs and Switch or maybe Connect Device or Cable.
6 0
3 years ago
Other questions:
  • How can website illustrate cooperations and kidness?
    8·1 answer
  • Why might your digital footprint be important when you are applying for collage
    13·1 answer
  • All of the following are challenges presented by changing technology as it relates to the special events field EXCEPT: A. the ab
    13·1 answer
  • Availability is an essential part of ________ security, and user behavior analysis and application analysis provide the data nee
    14·1 answer
  • Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (a
    14·1 answer
  • You want to deploy a software package that's available to all users in the domain if they want to use it, but you don't want the
    7·1 answer
  • What is the purpose of using variables in programming?
    11·1 answer
  • There are several design goals in building an operating system; for example, resource utilization, timeliness, robustness and so
    11·1 answer
  • Given the following array definition, write a constant declaration named ArraySize that automatically calculates the size in byt
    5·1 answer
  • Which of the following is not a key component of a structure?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!