Question: charityDonations is a HashMap with String key type and Integer value type, representing the name of a donor and the amount of a donation. Integer

charityDonations is a HashMap with String key type and Integer value type, representing the name of a donor and the amount of a donation. Integer numData is read from input. Complete the for loop to read numData strings from input. For each string read:
If the string is a key in charityDonations, then output the key followed by "->", and the value associated with the key.
Otherwise, output the string followed by ": not a key".
Ex: If the input is:
3
Tia Dax Ani
then the output is:
Tia: not a key
Dax->25
Ani: not a key
import java.util.Scanner;
import java.util.HashMap;
public class CharityDonations {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
HashMap charityDonations = new HashMap();
String donorName;
int giftValue;
int numData;
int i;
charityDonations.put("Bob",80);
charityDonations.put("Pat",70);
charityDonations.put("Dax",25);
charityDonations.put("Meg",10);
numData = scnr.nextInt();
for (i =0; i < numData; ++i){
/* Your code goes here */
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!