Using NRIC.no to calculate and retrieve last alphabet

• 04-15-2010, 04:56 AM
Roselicious
Using NRIC.no to calculate and retrieve last alphabet
Hi guys

Will like some help here. How am I to extract out the 7928964 from
S7928964G and how am I to convert this string to int format?

The check digit of the NRIC No. is the official reference which is determined as follows:For example: NRIC No.(with official reference) =
S 7928964 G

Step 1: Multiply each digit by the following weights:
NRIC No.: 7 9 2 8 9 6 4
Weights: 2 7 6 5 4 3 2
Products: 14 63 12 40 36 18 8

Step 2: Sum up all the products found in step 1:
Sum: 14 + 63 + 12 + 40 + 36 + 18 + 8 = 191

Step 3: Find the remainder when the sum is divided by 11.
Remainder: 191 / 11 gives remainder of 4

Step 4: Take 11 – remainder to get the check digit.
Check digit: 11 – 4 = 7

Step 5: Look up the following table to get the official reference:
Check Digit 1 2 3 4 5 6 7 8 9 10 11
Reference A B C D E F G H I Z J
Official Reference: G

Will appreciate if some hints given. Am kind of confused over here:confused:
• 04-15-2010, 05:03 AM
Fubarable
You could use regular expressions, but I have a feeling that this is for an introductory programming course, and if so, I'd recommend that you simply use substring to extract the String of interest. Once you have the sub string with the numeric part, you could iterate through the String using a for loop going from 0 to the String's length(), and can extract each char with String#charAt(int index) method. Convert to int with Integer.parseInt(String.valueOf(myChar))....

Have fun!
• 04-15-2010, 04:20 PM
Roselicious
Then how to reference to the table ? Via search method ?
• 04-15-2010, 06:33 PM
Fubarable
Are you responsible for creating this look up table? If so, I see two possible solutions, either use a HashMap<Integer, Character>, or you could do simple char math:

Code:

`char referenceChar = (char)('A' + checkDigit - 1);  // note code not tested yet`