PLEASE ANSWER ALL (JAVA) - There are 4 tasks
Imagine you're developing a Pokemon game, and you need to implement the battle party mechanic. Recall that the player's party can 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 TASK: Write a public static method called getPIDs that has a parameter of type Map called nameTOPID (keys are student names and values are student PIDs). It should return a HashSet containing all PIDs in nameTOPID HINT: You are guaranteed that nameTOPID is non-empty Sample Input: Rick Morty A12345678 A87654321 Sample Output: A12345678 A87654321 The Queue is an Abstract Data Type (ADT) that is a "First In, First Out" data type because the first element to be added to it is the first one to be removed (much like a "queue", aka "line", at a grocery store) TASK: Write a class called StringQueue that the following properties: It should have a private instance variable of type LinkedList called elements that will store all the elements of the Queue It must have a no-parameter constructor that initializes the elements instance variable to an empty LinkedList It must have an instance method called enqueue that has one parameter of type String called element. It should add element to the back of the elements instance variable without returning anything It must have an instance method called peek that has no parameters. It should return the element at the front of the elements instance variable (without removing it). If no elements exist, it should return null It must have an instance method called dequeue that has no parameters. It should remove and return the element at the front of the elements instance variable. If no elements exist, it should return null It must have an instance method called size that has no parameters. It should return the number of elements currently in the elements instance variable HINT: You should be able to implement each method using just a single method call to the LinkedList instance variable Sample Input: Niema Gerald Shreeman Laura Utkrisht Sample Output: CORRECT TASK: Write a public static method called removeUnwantedValues that has a parameter of type LinkedList called allValues followed by a parameter of type Set called unwantedValues. It should remove all elements of allValues that are in unwantedValues, and it should not return anything. HINT: You can assume that both allvalues and unwantedValues are non-empty EXAMPLE: If we were to run the following lines of code: // add numbers to allValues LinkedList allValues = new LinkedList(); allValues.add(1); allvalues.add(2); allValues.add(3); allValues.add(1); allvalues.add(2); allValues.add(3); allvalues.add(1): allvalues.add(2); allvalues.add(3); : // add numbers we want to remove HashSet Integer> unwantedValues = new HashSet unwantedValues.add(1); unwantedValues.add(3); // remove them and print removeUnwantedValues(allValues, unwantedValues) : System.out.println(allValues); We should print the following: [2, 2, 2] Sample Input: 1 2 3 1 2 3 1 2 3 1 3 Sample Output: 2 2 2 Imagine you're developing a Pokemon game, and you need to implement the battle party mechanic. Recall that the player's party can 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 TASK: Write a public static method called getPIDs that has a parameter of type Map called nameTOPID (keys are student names and values are student PIDs). It should return a HashSet containing all PIDs in nameTOPID HINT: You are guaranteed that nameTOPID is non-empty Sample Input: Rick Morty A12345678 A87654321 Sample Output: A12345678 A87654321 The Queue is an Abstract Data Type (ADT) that is a "First In, First Out" data type because the first element to be added to it is the first one to be removed (much like a "queue", aka "line", at a grocery store) TASK: Write a class called StringQueue that the following properties: It should have a private instance variable of type LinkedList called elements that will store all the elements of the Queue It must have a no-parameter constructor that initializes the elements instance variable to an empty LinkedList It must have an instance method called enqueue that has one parameter of type String called element. It should add element to the back of the elements instance variable without returning anything It must have an instance method called peek that has no parameters. It should return the element at the front of the elements instance variable (without removing it). If no elements exist, it should return null It must have an instance method called dequeue that has no parameters. It should remove and return the element at the front of the elements instance variable. If no elements exist, it should return null It must have an instance method called size that has no parameters. It should return the number of elements currently in the elements instance variable HINT: You should be able to implement each method using just a single method call to the LinkedList instance variable Sample Input: Niema Gerald Shreeman Laura Utkrisht Sample Output: CORRECT TASK: Write a public static method called removeUnwantedValues that has a parameter of type LinkedList called allValues followed by a parameter of type Set called unwantedValues. It should remove all elements of allValues that are in unwantedValues, and it should not return anything. HINT: You can assume that both allvalues and unwantedValues are non-empty EXAMPLE: If we were to run the following lines of code: // add numbers to allValues LinkedList allValues = new LinkedList(); allValues.add(1); allvalues.add(2); allValues.add(3); allValues.add(1); allvalues.add(2); allValues.add(3); allvalues.add(1): allvalues.add(2); allvalues.add(3); : // add numbers we want to remove HashSet Integer> unwantedValues = new HashSet unwantedValues.add(1); unwantedValues.add(3); // remove them and print removeUnwantedValues(allValues, unwantedValues) : System.out.println(allValues); We should print the following: [2, 2, 2] Sample Input: 1 2 3 1 2 3 1 2 3 1 3 Sample Output: 2 2 2