Results 1 to 4 of 4
 04152010, 04:56 AM #1Member
 Join Date
 Apr 2010
 Posts
 24
 Rep Power
 0
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:

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!
 04152010, 04:20 PM #3Member
 Join Date
 Apr 2010
 Posts
 24
 Rep Power
 0
Then how to reference to the table ? Via search method ?

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:
Java Code:char referenceChar = (char)('A' + checkDigit  1); // note code not tested yet
Similar Threads

Java Alphabet problem
By hailkush in forum New To JavaReplies: 0Last Post: 03062010, 04:11 PM 
Alphabet timer help.
By kosok in forum New To JavaReplies: 2Last Post: 12242008, 06:05 PM 
Listing the alphabet (beginner)
By SuperOnion in forum New To JavaReplies: 3Last Post: 12222008, 03:23 AM 
calculate fft
By ram.west in forum Advanced JavaReplies: 2Last Post: 08272008, 03:05 AM 
Calculate what e1 and e2 should be
By Legoland in forum New To JavaReplies: 11Last Post: 07022007, 06:01 PM
Bookmarks