Question: lodgerData is a HashMap with String key type and Character value type, representing the name and room label of a guest. Integer numToRead is read

lodgerData is a HashMap with String key type and Character value type, representing the name and room label of a guest. Integer numToRead is read from input. Then numToRead key-value pairs are read from input and inserted into lodgerData. Output each key in the HashMap followed by "; ".
Ex: If the input is:
2
Taj G Noa Z
then one possible output is:
All keys found: Noa; Taj;
Note: The order of the keys is not guaranteed in a HashMap.
import java.util.Scanner;
import java.util.HashMap;
public class RoomReservation {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
HashMap lodgerData = new HashMap();
String guestName;
char roomLabel;
int numToRead;
int i;
numToRead = scnr.nextInt();
for (i =0; i < numToRead; ++i){
guestName = scnr.next();
roomLabel = scnr.next().charAt(0);
lodgerData.put(guestName, roomLabel);
}
System.out.print("All keys found: ");
/* Your code goes here */
System.out.println();
}
}

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!