Question

Write a Java program that is able to apply a hash function to a first and...

Write a Java program that is able to apply a hash function to a first and last name (key) of a person, and lookup the appropriate index in a hash table modeling a telephone directory. The telephone number (value) should be returned on doing a lookup (you can pre-populate the table with 20 entries for this purpose). You can use existing Java code (or libraries) to model the hash table, however, your program should be customized to use the hash table structure appropriately.

Demonstrate that your program works by providing meaningful console messages that walk the tester through the search function in the directory.

Call your primary tester file HashTableImplementation.java

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi... The code for the above requirement is below.The Code is tested and verified.Pls add more console messages if required. If any more details are required, comment. Hit a "LIKE" if found useful

import java.util.*;
  
public class HashTableImplementation {
public static void main(String[] args)
{
  
// Creating an empty Hashtable
Hashtable<String,String> hash_table =
new Hashtable<String,String>();
  
// Putting values in the table
hash_table.put("Ram vare", "9600189673");
hash_table.put("Veer pin", "918876545");
hash_table.put("Sham lea", "789009123");
hash_table.put("Reyaan rea", "7899076543");
hash_table.put("Ryan pil", "786666666");
  
// Displaying the Hashtable
System.out.println("Initial Table is: " + hash_table);
  
// Display the Value
System.out.println("The telephone number is " + hash_table.get("Ram vare"));
  
  
  
}
}

Output

------

$javac HashTableImplementation.java

Initial Table is: {Sham lea=789009123, Ryan pil=786666666, Reyaan rea=7899076543, Veer pin=918876545, Ram vare=9600189673}
The telephone number is 9600189673
Add a comment
Know the answer?
Add Answer to:
Write a Java program that is able to apply a hash function to a first and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a hash function to implement a digit-folding approach in the hash function. Your program should...

    Write a hash function to implement a digit-folding approach in the hash function. Your program should work for any array size and any key length. Use linear probing. Accessing a group of digits in a number may be easier than you think. Does it matter if the array size is not a multiple of 10?(Written in Java)

  • Write a hash function to implement a digit-folding approach in the hash function. Your program should...

    Write a hash function to implement a digit-folding approach in the hash function. Your program should work for any array size and any key length. Use linear probing. Accessing a group of digits in a number may be easier than you think. Does it matter if the array size is not a multiple of 10? #java#withcomments please

  • Write a Java program that creates and manipulates a directory of names, telephone numbers. The following...

    Write a Java program that creates and manipulates a directory of names, telephone numbers. The following information will be stored for each person in the directory: - Name (Last, First) - Home telephone number You should keep the entire collection ordered by key value (the combination of last and first names). Your program should be able to perform the following basic functions: - Search and display the contents of a particular entry - Display the entire directory - Delete an...

  • Write a java program that demonstrates recursion. This program can be in a java GUI frame...

    Write a java program that demonstrates recursion. This program can be in a java GUI frame or as a console application. On this one it is up to you. (It would probably work better as a console program for this particular program.) The input for this program is a number of boxes. Ask the user for this with a textbox or a prompt on the command line. Demonstrate recursion with a function called LoadTruck() that takes a number of boxes...

  • April 22, 2019 at 00:23 Submit a java program that utilizes Hash Maps. Write three functions...

    April 22, 2019 at 00:23 Submit a java program that utilizes Hash Maps. Write three functions for your program. Pass a String to the first function to Add a Color to the Hashmap Pass the Key to the second function to check if a certain Key is present in the Hashmap. Your function should output whether the key is present or not. Pass a Color String to the third function to check if a certain Color is present in the...

  • ( IN JAVA): Write a program that reads each line in a file, and writes them...

    ( IN JAVA): Write a program that reads each line in a file, and writes them out in reverse order into another file. This program should ask the user for the name of an input file, and the name of the output file. If the input file contains: Mary had a little lamb Its fleece was white as snow And everywhere that Mary went The lamb was sure to go Then the output file should end up containing: The lamb...

  • Write a C program countFiles.c to be executed on the command line as follows: countFiles <directory> The program...

    Write a C program countFiles.c to be executed on the command line as follows: countFiles <directory> The program should count the (regular) files in the specified directory as well as all subdirectories and output the total number on the console. Files and subdirectories whose names .start with should be ignored! To do this, define a function int countFilesRec(char* dirName)that dirName returns the number of (regular) files in the directory and all the subdirectories. Call the function recursively to count the...

  • IN JAVA USING ECLIPSE The objective of this assignment is to create your own hash table...

    IN JAVA USING ECLIPSE The objective of this assignment is to create your own hash table class to hold employees and their ID numbers. You'll create an employee class to hold each person's key (id number) and value (name). Flow of the main program: Create an instance of your hash table class in your main method. Read in the Employees.txt file and store the names and ID numbers into Employee objects and store those in your hash table using the...

  • This should be in Java Create a simple hash table You should use an array for...

    This should be in Java Create a simple hash table You should use an array for the hash table, start with a size of 5 and when you get to 80% capacity double the size of your array each time. You should create a class to hold the data, which will be a key, value pair You should use an integer for you key, and a String for your value. For this lab assignment, we will keep it simple Use...

  • PROGRAM DESCRIPTION Implement a hash table class. Your hash table should resolve collisions by chaining and...

    PROGRAM DESCRIPTION Implement a hash table class. Your hash table should resolve collisions by chaining and use the multiplication method to generate hash keys. You may use your own linked list code from a previous assignment or you can use a standard sequence container. Partial definitions for the hash table class and a generic data class are provided (C++ and Java versions). You may use them as a starting point if you wish. If you choose to design your own...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT