ලේසියෙන්ම හොයාගන්න මෙතනින්

ජාතික හැදුනුම්පත් අංකයෙන් උපන්දිනය හොයන්න Java වැඩසටහනක් ලියමු.

ඔක්කොටම කලින් දැනගමු මේකට තර්කය මොකක්ද කියල. ජාතික හැදුනුම්පතේ පිටට එක පාරම පෙන්න උපන්දිනය සඳහන් වෙලා නෑ. අපිට පොඩි ගණිතකර්ම ටිකක් කරලා, ඕක හොයා ගන්න පුළුවන්. ජාතික හැදුනුම්පත් අංකය ඉලක්කම් 9 කින් සමන්විතයි. අගට V අකුරකුත් ඇතුලත් වෙනවා. මේ ඉලක්කම් 9 න් මුල් ඉලක්කම් 5 විතරයි අපට උවමනා කරන්නේ. මම මේ සඳහා වැඩසටහන්කරණයට යොදා ගන්නේ Java භාෂාවයි. ඒ වගේම IDE එක ලෙස Net Beans යොදා ගන්නවා. 
උදාහරණයක්‌ විදියට අපි මෙන්න මෙහෙම ජාතික හැදුනුම්පත් අංකයක් සලකමු. 901494212 V
මෙහි මුල් ඉලක්කම් 5 පමණක් සැලකුවම, 90149. මෙහි මුල් ඉලක්කම් 2 න් කියවෙන්නේ ඉපදුනු අවුරුද්දයි. අවසාන ඉලක්කම් 3 න් පෙන්වන්නේ ඉපදුනු දවසට, ජනවාරි 1 සිට ඇති දින ප්‍රමාණයයි. ඒ පිරිමි අය සඳහායි. ගැහැණු අයගේනම්, ජනවාරි 1 සිට, උපන්දිනයට ඇති දින ප්‍රමාණයට, තවත් 500 ක් එකතු කරනු ලැබේ. ඔන්න ඔහොම තමා, අපේ උපන්දිනය, ජාතික හැදුනම්පත ඇතුලේ හැංගිලා ඉන්නේ. 
Program එකක් ලියන්න කලින් එකට උවමනා කරන තර්ක ගොඩ නගන්න. මෙහිදිනම් කොහොමද අපි උපන් අවුරුද්ද වෙනමත්, උපන් මාසය, උපන් දිනය වෙන් කරගන්නේ කියල. අනික අධික අවුරුද්දක්නම් වැඩේ අයෙත් වෙනස් වෙනවා. ඒ නිසා හිතන්න දේවල් ගොඩයි.
Program එකක් ලියද්දි එක එක විදියට කරන්න පුළුවන්. එක දෙයක් කරන්න, එකම විදියක් නෙවෙයි තියෙන්නේ. ඒ දේ අමතක කරන්න එපා. මං මෙතැනදී සරලම Java වල වැඩි වැඩ නැතිව, සරලම ගණිත කර්ම පමණක් යොදාගෙන කරලා පෙන්වන්නම්. (තව කෙනෙකුට පුළුවන් StringTokenizer, StringBuffer යොදාගන්න ). උපන් අවුරුද්ද, හා උපන්දිනයට ජනවාරි 1 සිට දින ගණන වෙන් කරගන්න අපි මෙහෙම කරමු. මං කිවනේ මුල් ඉලක්කම් 5 විතරයි ඕනෑ කියල. එහෙනම් ඉලක්කම් 9 ක් වන සංඛ්‍යාව 104 බෙදන්න. එතකොට අපට එන පුර්ණ සංඛ්‍යාව මුල් ඉලක්කම් 5 යි. ඒක වෙනම int විචල්‍යකට (x) save කරන්න. දැන් ඒ සංඛ්‍යාව 103 බෙදල පුර්ණ සංඛ්‍යාව තවත් විචල්‍යකටත් (y), සංඛ්‍යාව 103 බෙදල ඉතිරිය තවත් විචල්‍යකටත් (z) save කරගන්න.
int x = 901494212/10000;
int y = x/1000;
int z = x%1000;
දැන් y විචල්‍යයේ උපන් අවුරුද්දත්. z විචල්‍යයේ උපන්දිනයට ජනවාරි 1 සිට දින ප්‍රමාණයත් සටහන් වී ඇත. එහෙනම් දැන් අවුරුද්ද හරි. දැන් මාසය හා දිනය හොයාගන්න ලේසි නෑ. ඉස්සෙල්ලම අපි බලන්න ඕනෑ උපන් අවුරුද්ද, අධික අවුරුද්දක් ද නැද්ද කියල. එකට අවුරුද්ද ඉතිරි නැතිව 4 න් බෙදෙනවද බලන්න. ඉතිරි නැතිව බෙදෙනවානම් අධික අවුරුද්දක් වෙනවා. එහෙම නැත්නම් අධික අවුරුද්දක් නෙවයි. ඊට පස්සේ බලන්න ඕනෑ අදාල ජාතික හැදුනුම්පත් අයිතිකරු පිරිමිද, ගැහැනුද කියල. පිරිමි නම්, z විචල්‍යයේ අගය 1 ත් 365 ත් අතර (1 <= z <=365)  (අධික අවුරුද්දක් නම් 366) වෙන්න ඕනෑ. ගැහැණු නම්  z විචල්‍යයේ අගය 501 ත් 865 ත් අතර (501 <= z <=865)  (අධික අවුරුද්දක් නම් 866) වෙන්න ඕනෑ.
දැන් ඉතින් වෙන වෙනම පරික්ෂා කරන්න ඕනෑ, code ලියන්න ඕනෑ, අධික අවුරුද්දක උපන් පිරිමි කෙනෙක් නම්, අධික අවුරුද්දක උපන් ගැහැණු කෙනෙක් නම්, අධික අවුරුද්දක් නොවන අවුරුද්දක උපන් පිරිමි කෙනෙක් නම්,  අධික අවුරුද්දක් නොවන අවුරුද්දක උපන් ගැහැණු කෙනෙක් නම්, යනාදී වශයෙන් උපන්දිනය හොයන්න ඕනෑ කරනවා. if, else if, else යොදාගෙන අපට පුළුවන් දින check කරන්න.

ID.java
import java.util.*;
class ID{
public static void main (String[] hans) {
Scanner hansa=new Scanner(System.in);
int id,year;
String byear;
M n = new M();
System.out.print("Enter Identity Card Number : ");
id=hansa.nextInt();
String x = id+"";
if(x.length()==9){
year = id/10000000;
int y = (id-(year*10000000))/10000;
if(year%4==0){
if(year>48&&year<100)
byear=19+""+year;
else
byear = 20+""+year;
if(y<367&&y>0){
System.out.println("????????");
System.out.print(byear+" ");
n.d366m(y);
}else if(y>500&&y<867){
System.out.println("Female");
System.out.print(byear+" ");
n.d366f(y);
}else{
System.out.println("Invalid ID Number");
}

}else{
if(year>48&&year<100)
byear=19+""+year;
else
byear = 20+""+year;
if(y<367&&y>0){
System.out.println("????????");
System.out.print(byear+" ");
n.d365m(y);
}else if(y>500&&y<866){
System.out.println("Female");
System.out.print(byear+" ");
n.d365f(y);
}else{
System.out.println("Invalid ID Number");
}
}
}else{
System.out.println("retry");
}
}

}


class M{
void d365m(int k){
int temp;
if(k<=365&&k>=335){
temp = k-335;
System.out.print("December "+temp);
}else if(k<=334&&k>=305){
temp = k-305;
System.out.print("November "+temp);
}else if(k<=304&&k>=274){
temp = k-274;
System.out.print("October "+temp);
}else if(k<=273&&k>=244){
temp = k-244;
System.out.print("September "+temp);
}else if(k<=243&&k>=214){
temp = k-214;
System.out.print("August "+temp);
}else if(k<=213&&k>=183){
temp = k-183;
System.out.print("July "+temp);
}else if(k<=182&&k>=152){
temp = k-152;
System.out.print("June "+temp);
}else if(k<=151&&k>=121){
temp = k-121;
System.out.print("May "+temp);
}else if(k<=120&&k>=91){
temp = k-91;
System.out.print("April "+temp);
}else if(k<=90&&k>=60){
temp = k-60;
System.out.print("March "+temp);
}else if(k<=59&&k>=32){
temp = k-32;
System.out.print("February "+temp);
}else if(k<=31&&k>=1){
temp = k;
System.out.print("January "+temp);
}
}

void d366m(int k){
int temp;
if(k<=366&&k>=336){
temp = k-336;
System.out.print("December "+temp);
}else if(k<=335&&k>=306){
temp = k-306;
System.out.print("November "+temp);
}else if(k<=305&&k>=275){
temp = k-275;
System.out.print("October "+temp);
}else if(k<=274&&k>=245){
temp = k-245;
System.out.print("September "+temp);
}else if(k<=244&&k>=215){
temp = k-215;
System.out.print("August "+temp);
}else if(k<=214&&k>=184){
temp = k-184;
System.out.print("July "+temp);
}else if(k<=183&&k>=153){
temp = k-153;
System.out.print("June "+temp);
}else if(k<=152&&k>=122){
temp = k-122;
System.out.print("May "+temp);
}else if(k<=121&&k>=92){
temp = k-92;
System.out.print("April "+temp);
}else if(k<=91&&k>=61){
temp = k-61;
System.out.print("March "+temp);
}else if(k<=60&&k>=32){
temp = k-32;
System.out.print("February "+temp);
}else if(k<=31&&k>=1){
temp = k;
System.out.print("January "+temp);
}
}

void d365f(int k){
int temp;
if(k<=865&&k>=835){
temp = k-835;
System.out.print("December "+temp);
}else if(k<=834&&k>=805){
temp = k-805;
System.out.print("November "+temp);
}else if(k<=804&&k>=774){
temp = k-774;
System.out.print("October "+temp);
}else if(k<=773&&k>=744){
temp = k-744;
System.out.print("September "+temp);
}else if(k<=743&&k>=714){
temp = k-714;
System.out.print("August "+temp);
}else if(k<=713&&k>=683){
temp = k-683;
System.out.print("July "+temp);
}else if(k<=682&&k>=652){
temp = k-652;
System.out.print("June "+temp);
}else if(k<=651&&k>=621){
temp = k-621;
System.out.print("May "+temp);
}else if(k<=620&&k>=591){
temp = k-591;
System.out.print("April "+temp);
}else if(k<=590&&k>=560){
temp = k-560;
System.out.print("March "+temp);
}else if(k<=559&&k>=532){
temp = k-532;
System.out.print("February "+temp);
}else if(k<=531&&k>=501){
temp = k-500;
System.out.print("January "+temp);
}
}

void d366f(int k){
int temp;
if(k<=866&&k>=836){
temp = k-836;
System.out.print("December "+temp);
}else if(k<=835&&k>=806){
temp = k-806;
System.out.print("November "+temp);
}else if(k<=805&&k>=775){
temp = k-775;
System.out.print("October "+temp);
}else if(k<=774&&k>=745){
temp = k-745;
System.out.print("September "+temp);
}else if(k<=744&&k>=715){
temp = k-715;
System.out.print("August "+temp);
}else if(k<=714&&k>=684){
temp = k-684;
System.out.print("July "+temp);
}else if(k<=683&&k>=653){
temp = k-653;
System.out.print("June "+temp);
}else if(k<=652&&k>=622){
temp = k-622;
System.out.print("May "+temp);
}else if(k<=621&&k>=592){
temp = k-592;
System.out.print("April "+temp);
}else if(k<=591&&k>=561){
temp = k-561;
System.out.print("March "+temp);
}else if(k<=560&&k>=532){
temp = k-532;
System.out.print("February "+temp);
}else if(k<=531&&k>=501){
temp = k-500;
System.out.print("January "+temp);
}
}
}

NetBeans Project Files මෙතනින් බා ගන්න පුළුවන්...
http://www.mediafire.com/?sr2tn9kfp01qm4i

1 comment :

  1. Dear HANSA , I don’t know you personally. Whilst surfing the web I stumble on your attempts for development. I put it on record wishing you a bright future. Computer science was not born overnight. It is the dedication and surmounting challenges that non-influential people like you who contribute by experimentation that enriches computer technology. Human civilization can be changed by the brilliance or the hand of a person like you. Your efforts will be written in gold in the computer history. I have no doubt that your future will be bright. The world of computers need dedicated people like you. If computing is the sky it is those who share their knowledge and wisdom are the stars. A sky without stars is not beautiful. Lastly my warm wishes to you whom I have never seen, met or spoken.AERO TNT.

    ReplyDelete