Results 1 to 4 of 4
  1. #1
    Roselicious is offline Member
    Join Date
    Apr 2010
    Posts
    24
    Rep Power
    0

    Default 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:

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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!

  3. #3
    Roselicious is offline Member
    Join Date
    Apr 2010
    Posts
    24
    Rep Power
    0

    Default

    Then how to reference to the table ? Via search method ?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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

  1. Java Alphabet problem
    By hailkush in forum New To Java
    Replies: 0
    Last Post: 03-06-2010, 04:11 PM
  2. Alphabet timer help.
    By kosok in forum New To Java
    Replies: 2
    Last Post: 12-24-2008, 06:05 PM
  3. Listing the alphabet (beginner)
    By SuperOnion in forum New To Java
    Replies: 3
    Last Post: 12-22-2008, 03:23 AM
  4. calculate fft
    By ram.west in forum Advanced Java
    Replies: 2
    Last Post: 08-27-2008, 03:05 AM
  5. Calculate what e1 and e2 should be
    By Legoland in forum New To Java
    Replies: 11
    Last Post: 07-02-2007, 06:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •