Question: Lab 14.1 Suppose you write a program to keep track of the friends of all the students in your class using a HashMap. What would

Lab 14.1

Suppose you write a program to keep track of the friends of all the students in your class using a HashMap. What would you use for the keys? What would you use for the values?

Type your answers in the space provided below.

Lab 14.2

Write a program named Friends that stores the following information in a HashMap:

Sue is friends with Bob, Jose, Alex, and Cathy Cathy is friends with Bob and Alex Bob is friends with Alex, Jose, and Jerry

After storing the information, keep prompting the user to enter a name until they enter "quit". If the name that is a key in the HashMap, print out the name and the list of friends. Otherwise print a message indicating that the name is not in the HashMap.

Sample Run (user input in color):

Enter a name ('quit' to end): Bob Here are the friends of Bob: [Alex, Jose, Jerry] Enter a name ('quit' to end): Cathy Here are the friends of Cathy: [Alex, Bob] Enter a name ('quit' to end): Sue Here are the friends of Sue: [Alex, Bob, Jose, Cathy] Enter a name ('quit' to end): Pete Awww, Pete has no friends :( Enter a name ('quit' to end): Quit OK, bye for now!

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 Databases Questions!