Question: Java!!! Write a program named Lab 2 7 B . a . Create a secondary class named Gadget. It should have the following: i .

Java!!!
Write a program named Lab27B.
a. Create a secondary class named Gadget. It should have the following:
i. Two instance variables: the gadget ID (int) and the gadget name (String)
ii. A constructor that receives an int and a String parameter and fills in both
instance variables.
iii. An int method to return the gadget ID
iv. A toString method to return a string with the instance variables.
b. In your main class do the following:
i. Write an int method that receives an int parameter (the gadget ID) and returns
the result of performing the hash function on the parameter.
The hash function will be key %20.
ii. In the main method:
Create an array of 20 Gadget objects.
Read the gadget IDs and names in from the text file (Input27B.txt).(You
don't know how many customers there will be, but it will be 20). For
each one:
a. Calculate the hash code by sending the gadget ID to your
hashing function method.
b. Write the gadget's name and hash function result
c. Create a Gadget object
d. Add the object to your hash table array at the index returned by
your hash function method. If there is a collision, use the
quadratic probing method to find an empty one. Place the
object there.
If you get to the end of the array, go back up to index 0 again.
After all customers have been added to the hash table, print the hash
table array. (Don't print the nulls, though.) Print the index number
before each gadget object's info.
(You'll probably need to write a for loop for this instead of using
Arrays.toString.)
InputFile
1245 Bookend
1300 Can opener
1221 Microwave
1294 Clock
1311 Refrigerator
1388 Ice maker
1120 Radio
1400 Counter top range
Java!!! Write a program named Lab 2 7 B . a .

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