Question: X 1 2 9 3 : Compute hash key from string Write a function that computes a hash key for a student ID . The
X: 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: digits, followed by a hyphen followed by
more digits. However, ids are often written without the hyphen. So both of these IDs are valid and the same:
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 idtoCharArray;
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 ie 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
hashKey
Your Answer:
Feedback
public int hashKeyString id int size
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
