Visit www.myprogramminglab.com to complete select exercises online and get instant feedback.
Exercise
In social networking websites, people link to their friends to form a social network. Write a program that uses HashMaps to store the data for such a network. Your program should read from a file that specifies the network connections for different usernames. The file should have the following format to specify a link:
source_usernamefriend_username
There should be an entry for each link, one per line. Here is a sample file for five usernames:
iba java_guruiba crishaiba duckycrisha java_gurucrisha ibaducky java_guruducky ibajava_guru ibajava_guru crishaj ava_guru duckywitless java_guru
In this network, everyone links to java_guru as a friend. iba is friends with java_ guru, crisha, and ducky. Note that links are not bidirectional; wittless links with java_guru but java_guru does not link with wittless.
First, create a User class that has an instance variable to store the user’s name and another instance variable that is of type HashSet
• Upon startup, read the data file and populate the HashMap and HashSet data structures according to the links specified in the file.
• Allow the user to enter a name.
• If the name exists in the map, then output all usernames that are one link away from the user entered.
• If the name exists in the map, then output all usernames that are two links away from the user entered. To accomplish this in a general way, you might consider writing a recursive subroutine.
Do not forget that your User class must override the hashCode and equals methods.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.