Need help with your Discussion

Get a timely done, PLAGIARISM-FREE paper
from our highly-qualified writers!

glass
pen
clip
papers
heaphones

NLC Computer Science Lab Report

NLC Computer Science Lab Report

NLC Computer Science Lab Report

Description

Lab Assignment 27 (Hashing)

1.Write a program named Lab27A that will make a hash table of customer names and customer ID numbers. The customer ID number (integer) will be the key for each entry.

a.Create a class named Customer that will have

i.Two instance variables: the customer ID (int) and the customer name (String)

ii.A constructor that receives an int and a String parameter and fills in both instance variables.

iii.A void method to return the customer ID

iv.A toString method to print both variables (with labels as always)

b.Back in the main class, do the following:

i.Write an int method that receives an int parameter (the customer ID) and returns the result of performing the hash function on the parameter.

The hash function separates the key into digits and adds the digits together. If that sum has more than one digit, then the digits of the sum are added together. This will be repeated until the final result is only one digit long (hint: it must be < 10).

Example: hash(83945) = 8 + 3 + 9 + 4 + 5 = 29

But 29 has 2 digits so we do it again ? 2 + 9 = 11

11 still has 2 digits, so we do it one more time ? 1 + 1 = 2

Thus, hash(83045) = 2

ii.In the main method:

1.Create an array of 10 Customer objects.

2.Read the customer ID’s and names in from the text file (Lab27A.txt). (You don’t know how many customers there will be, but it will be < 10). For each one:

a. Calculate the hash code by sending the customer ID to your hashing function method

b.Write the customer’s name and hash function result

c.Create a Customer object

d.Add the object to your hash table array at the index returned by your hash function method. If there is a collision, then keep moving forward one array location at a time until you find an empty one (linear probing). Place the object there.

If you get to the end of the array, go back up to index 0 again.

3.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 customer object’s info.
(You’ll probably need to write a for loop for this instead of using Arrays.toString.)

Hint: To check if an array named arr has an object at location i, you would write:

if (arr[i] != null)

2.Write a program named Lab27B where you will create a hash table of “gadgets” using a different hash function and quadratic probing.

a.Create a class named Gadget that you will make objects of. 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.A void method to return the gadget ID

iv.A toString method to print both variables (with labels)

b.In your main class do the same things you did for Lab27A, but with following changes.

i.The hash table array should have a length of 20.

ii.Read the data from Lab27B.txt

iii.The hash function will be key % 20

iv.You should use quadratic probing to find a new location for an entry if a collision occurs.

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Order Solution Now

Our Service Charter


1. Professional & Expert Writers: Eminence Papers only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Eminence Papers are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Eminence Papers are known for the timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Eminence Papers, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

We Can Write It for You! Enjoy 20% OFF on This Order. Use Code SAVE20

Stuck with your Assignment?

Enjoy 20% OFF Today
Use code SAVE20