Write a program named Lab27A that will make a hash table of customer names and customer...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 iii. instance variables. 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 empty one (linear probing). Place the object there. find an 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) 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 iii. instance variables. 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 empty one (linear probing). Place the object there. find an 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)
Expert Answer:
Answer rating: 100% (QA)
Heres the implementation of the Customer class and the Lab27A class as described java import javaioF... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Which of these is located farthest south? Crete O Sardinia Sicily Corsica
-
The percentages of the workforce in unions and the percent- ages of worker hours lost due to strikes are compared by the scatterplot in Fig. 15 for the 50 states, except Alaska and Nebraska. Let U be...
-
The isotope 198 79 Au (atomic mass = 197.968 u) of gold has a half-life of 2.69 days and is used in cancer therapy. What mass (in grams) of this isotope is required to produce an activity of 315 Ci?
-
From a historical perspective, identify three precedented systems that were replaced with unprecedented systems.
-
Hawkeye Corporation's balance sheet at December 31, 2016, is presented below. During 2017, the following transactions occurred. 1. On January 1, 2017, Hawkeye issued 1,200 shares of $40 par, 7%...
-
Find the total number of compounding periods and the interest rate per period for the investment. Nominal Term of Investment Interest (Annual) Rate (%) Compounded Compounding Periods Rate per Period...
-
Terri Lau and Lesley Morobe completed their MBA studies together at Wits University. They worked well together on their group assignments and during the year became firm friends. After graduation,...
-
Clarks Incorporated, a shoe retailer, sells boots in different styles. In early November the company starts selling "SunBoots" to customers for $50 per pair. When a customer purchases a pair of...
-
Mason ( single ) is a 5 0 percent shareholder in Angels Corporation ( an S Corporation ) . Mason receives a $ 1 9 0 , 5 0 0 salary working full time for Angels Corporation. Angels Corporation...
-
Blake Corporation acquired 1 0 0 percent of Shaw Corporation's voting shares on January 1 , 2 0 X 3 , at underlying book value. At that date, the book values and fair values of Shaw's assets and...
-
Ryan Terlecki organized a new Internet company, CapUniverse, Incorporated. The company specializes in baseball-type caps with logos printed on them. Ryan, who is never without a cap, believes that...
-
A process manufacturer reports the following: Conversion Percent Units Complete: Beginning work in process inventory 150,000 80% Units started this period 310,000 Units completed and transferred out...
-
Review the case study that led to the collapse of the CAREGROUP'S network. 1. Using the text information, critically assess the events surrounding case study and defend your position. 2. Be sure to...
-
Design a circuit which negative the content of any register and store it in the same register.
-
Using Program16.m(Houbolt method), solve Problem 11.20. Data From Problem 11.20:- The equations of motion of a two-degree-of-freedom system are given by \(2 \ddot{x}_{1}+6 x_{1}-2 x_{2}=5\) and...
-
Using Program16.m(Houbolt method), solve Problem 11.19. Data From Problem 11.19:- Using the central difference method, find the response of the system shown in Fig. 11.2 when \(F_{1}(t)=10 \sin 5 t\)...
-
Using the Wilson method with \(\theta=1.4\), solve Problem 11.18. Data From Problem 11.18:- Using the central difference method, find the response of the two-degree-of-freedom system shown in Fig....
Study smarter with the SolutionInn App