Question: X 1 2 9 3 : Compute hash key from string Write a function that computes a hash key for a student ID . The

X1293: Compute hash key from string
Write a function that computes a hash key for a student ID. The student ID is a String with the following format: 3 digits, followed by a hyphen (-), followed by 4 more digits. However, ids are often written without the hyphen. So, both of these IDs are valid and the same:
800-12345
80012345
Write a function that computes a hash key for the id passed as an argument. Remember that you can convert a String to a char array using the following line:
char digits[]= id.toCharArray();
Then you can loop through the digits array adding up each element. That produces a sum of the ASCII value of all the letters. Remember to skip (i.e., don't add) any character that is '-'(hyphen).
This sum you can then use with a mod operation with the second argument size to get the hash key.
Return this hash key.
Examples:
hashKey("834-1234",10)->1
hashKey("8341234",10)->1
Your Answer:
public int hashKey(String id, int size)
{
}
public int hashKey(String id, int size)
{
}

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