### From National Identity Card(NIC) print date of birth in java

The following numbering system is followed in order to assign this number:
• Digits 1 and 2: The year of birth
• Digits 3-5: The number of the day in the year on which the person's birth date falls.
• A male would be assigned the number 1-366 and a female the number 501-866. This is a way of confirming if the person's listed birth date is accurate. A male's birth date would be represented by the exact number of days, a female's birth date would be represented by the exact number of days + 500.
•    Example: The first five digits of the NIC for a male born on 1 January 1997   would be 97001; however, a female born on that same date would be 97501.
• Digits 6-8 are the serial number from the Record book maintained at the Department [for the Registration of Persons].
• Digit 9 is a check digit
• The letter V stands for voter and X for a non-voter. Example: a student who applies for a NIC at 16, at which age he/she does not have the right to vote, the number on his/her card will end with an X. Cards issued in 2007 (no exact date available) no longer make this distinction  everyone is issued numbers that end with the letter V.
Java version of NIC program is given bellow :

/**
* To change this template, choose Tools | Templates and open the template in
* the editor.
*/
package age;

import java.util.Scanner;

/**
*
* @author ACHCHUTHAN
*/
public class NIC_Details {

String id;
int month[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

public NIC_Details() {
Scanner input = new Scanner(System.in);
System.out.println("Enter Your NIC Number \nLike : 000000000V");
id = input.next();
}

public int getYear() {
return (1900 + Integer.parseInt(id.substring(0, 2)));
}

public int getDays() {
int d = Integer.parseInt(id.substring(2, 5));
if (d > 500) {
return (d - 500);
} else {
return d;
}
}

public void setMonth() {
int mo = 0, da = 0;
int days = getDays();

for (int i = 0; i < month.length; i++) {
if (days < month[i]) {
mo = i + 1;
da = days;
break;
} else {
days = days - month[i];
}
}
System.out.println("Month : " + mo + "\nDate : " + da);

}

public String getSex() {
String M = "Male", F = "Female";
int d = Integer.parseInt(id.substring(2, 5));
if (d > 500) {
return F;
} else {
return M;
}
}

public static void main(String[] args) {
NIC_Details N = new NIC_Details();
System.out.println("Your Deatials of Date of Birth from NIC Number");
System.out.println("Year : " + N.getYear());
N.setMonth();
System.out.println("Sex : " + N.getSex());
}
}

Output of this program :

run:
Like : 000000000V
900733550v
Your Deatials of Date of Birth from NIC Number
Year : 1990
Month : 3
Date : 13
Sex : Male
BUILD SUCCESSFUL (total time: 12 seconds)

1. CREATE FUNCTION ENTERPRISEDB.RESOLVENIC
( name_in IN varchar2 )
RETURN varchar
IS
cnumber date;
val1 number;
val2 number;
val3 number;
mo number;
da number;
days number;
yy varchar(100);
mm varchar(100);
dd varchar(100);
fulltxt varchar(100);

type montharr IS VARRAY(100) OF NUMERIC(10);
months montharr;

BEGIN
months := montharr(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

val1 := to_number( substr(name_in, 0, 2));
val1 := val1 + 1900;

val2 := to_number( substr(name_in, 3, 3));
IF val2 > 500 THEN
val2:=val2-500;
else
val2:=val2;
end if;

days := val2;

for i in months.first..months.last
loop
if days < months(i) then
mo := i ;
da := days;
EXIT;
else
days := days - months(i);
end if;
end loop;

yy := to_char( val1 ) ;
mm := to_char( mo ) ;
dd := to_char( da ) ;
fulltxt := concat( yy||'/', mm||'/');
fulltxt := concat( fulltxt, dd);
RETURN fulltxt ;

EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
END;
GO

// W.I.Sudusinghe
//wi.sudusinghe@gmail.com

2. thanks. this is really helpful!

3. can you give me a flowchart for this diagrame?

4. can you give me flowchart and algorithm for this?

5. the last digit of both NICs old and new have a check digit, do know how it is generated

6. Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work. fake id

7. How to find my nic number

Thank you for vising Java90.blogspot.com