Question: Declare variable testPerformance as a HashMap with String key type and Double value type, representing the name and test score of a student. Read integer

Declare variable testPerformance as a HashMap with String key type and Double value type, representing the name and test score of a student. Read integer dataCount from input. Then read dataCount key-value pairs from input and insert each into testPerformance. If the key already exists, do not replace the key's existing value with the new value.
Ex: If the input is:
3 Ron 84.5 Kim 79.0 Kim 88.0
then one possible output is:
Key: Ron, Value: 84.5 Key: Kim, Value: 79.0
import java.util.Scanner;
import java.util.HashMap;
public class ExamPerformance {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
String studentName;
double examScore;
int dataCount;
int i;
/* Any variable declarations go here */
/* Your code goes here */
// For each key in the HashMap, retrieve the value associated with the key
for (String key : testPerformance.keySet()){
System.out.println("Key: "+ key +", Value: "+ testPerformance.get(key));
}
}
}

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!