NEW NIC ALGORITHM JAVA 8
අලුත් NIC එකට පොඩි කෝඩ් කෑල්ල්ක් ලිව්ව. උබලට ඕනෙ විදියට වෙනස් කරගෙන පොඩ්ඩක් ටෙස්ට් කොරල බලල කියපල්ල හරිද කියල. උබලට ඕනෙ ප්රොජෙක්ට් වලින් ගෙඩිය පිටින්ම උස්සල පාවිච්චි කරපල්ල.
JAVA 8 එක්ක මහලොකු වෙලාවක් යන්නෙ නෑ. 
https://en.wikipedia.org/wiki/National_identity_card_(Sri_Lanka)
අලුත් NIC එකට පොඩි කෝඩ් කෑල්ල්ක් ලිව්ව. උබලට ඕනෙ විදියට වෙනස් කරගෙන පොඩ්ඩක් ටෙස්ට් කොරල බලල කියපල්ල හරිද කියල. උබලට ඕනෙ ප්රොජෙක්ට් වලින් ගෙඩිය පිටින්ම උස්සල පාවිච්චි කරපල්ල.
JAVA 8 එක්ක මහලොකු වෙලාවක් යන්නෙ නෑ. 
Code:
import java.time.LocalDate;
import java.time.Period;
import java.time.temporal.ChronoUnit;
/**
*
* @author Tharindu
*/
public class NicDetails {
private String birthDay, gender, fullAge;
private int age;
public NicDetails(String nic) {
setDetails(nic);
}
public String getBirthDay() {
return birthDay;
}
public int getAge() {
return age;
}
public String getGender() {
return gender;
}
public String getFullAge() {
return fullAge;
}
public static void main(String[] args) {
NicDetails nicDetails = new NicDetails("960621025v");
System.out.println(nicDetails.getBirthDay());
System.out.println(nicDetails.getGender());
System.out.println(nicDetails.getAge());
System.out.println(nicDetails.getFullAge());
}
private void setDetails(String nic) {
int year, days;
if (nic.length() == 10) { //OLD NIC-----------------------------------
year = Integer.parseInt("19" + nic.substring(0, 2));
days = Integer.parseInt(nic.substring(2, 5));
} else { //NEW NIC-----------------------------------
year = Integer.parseInt(nic.substring(0, 4));
days = Integer.parseInt(nic.substring(4, 7));
}
if (days > 500) {
setGender("Female");
days -= 500;
} else {
setGender("Male");
}
LocalDate date = LocalDate.ofYearDay(year, days);
if (!date.isLeapYear() && days > 60) {
date = date.plusDays(-1);
}
setBirthDay(date.toString());
//AGE-------------------------------------------------------------------
int oldYear = (int) ChronoUnit.YEARS.between(date, LocalDate.now());
setAge(oldYear);
Period elapsed = Period.between(date, LocalDate.now());
String text = oldYear + " years " + elapsed.getMonths() + " month(s) " + elapsed.getDays() + " day(s)";
setFullAge(text);
}
/**
* @param birthDay the birthDay to set
*/
private void setBirthDay(String birthDay) {
this.birthDay = birthDay;
}
/**
* @param gender the gender to set
*/
private void setGender(String gender) {
this.gender = gender;
}
/**
* @param fullAge the fullAge to set
*/
private void setFullAge(String fullAge) {
this.fullAge = fullAge;
}
/**
* @param age the age to set
*/
private void setAge(int age) {
this.age = age;
}
}
https://en.wikipedia.org/wiki/National_identity_card_(Sri_Lanka)





