Question: The SetTest Application Overview In this challenge, we revisit the concept of hashing with the Java HashSet. You will create a SetTest application that demonstrates
The SetTest Application
Overview
In this challenge, we revisit the concept of hashing with the Java HashSet. You will create a SetTest application that demonstrates creating and processing a generic Set limited to String objects, with the Set implemented as a HashSet. The application will include an inputSetNames method, a displaySetNames method, and a searchSetNames method.
Specifications
Create the skeleton for a program called SetTest.
Declare a private static Scanner object.
In method main, declare a generic Set called names that only accepts String objects. Use the Set implementation java.util.HashSet.
In method main, display a message explaining that a Set of names will be entered, displayed, and searched.
Call the method to input the names.
o Prompt and read the first name.
o Add the name to the names Set.
o Continue prompting and reading names until the user types end.
o Add each name to the names Set after user entry.
Call the method to display the names Set .
Call the method to search for a name in the names Set.
o Prompt and read a search name.
o Display the proper message indicating whether the search name was found. Hint: use the Set contains method.
o The user can continue to search for another name or enter end when finished searching.
Additional Requirements
Perform a short Internet search on HashSets and HashMaps and add a comment at the end of your program with a response to this question:
o What are the differences in the way HashSet and HashMap are internally implemented in Java? Do you think HashSet is preferred to HashMap for storing a collection of names? Why or why not? Cite your sources.
Sample Output
This program will prompt you to enter names into a Set. The names in the Set will be displayed. Finally, you will have an opportunity to search a name in the Set.
Add a name to the set; enter "end" to terminate input: Noah
Add a name to set; enter "end" to terminate input: Oliver
Add a name to set; enter "end" to terminate input: Sophia
Add a name to set; enter "end" to terminate input: Zoe
Add a name to set; enter "end" to terminate input: Liam
Add a name to set; enter "end" to terminate input: Oliver
Add a name to set; enter "end" to terminate input: end
Set: [Zoe, Oliver, Noah, Liam, Sophia]
Enter a search a name; enter "end" to terminate searching: Joe
Joe was not found in the set.
Enter a search name; enter "end" to terminate searching: sophia
sophia was not found in the set.
Enter a search name; enter "end" to terminate searching: Sophia
Sophia was found in the set.
Enter a search name; enter "end" to terminate searching: end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
