Created
November 15, 2021 11:58
-
-
Save Zelakolase/e41e563b4245d825a96f8ee8752a041a to your computer and use it in GitHub Desktop.
National ID to get data from
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
public class DTFromID { | |
static HashMap<String, String> GovIDMap = new HashMap<String, String>(){ | |
{ | |
put("01","Cairo"); put("02","Alexandria"); put("03","Portsaid"); put("04","Suez"); put("11","Damietta"); put("12","Daqahlia"); put("13","Sharkia"); put("14","Qalyobia"); put("15","Kafr El-sheikh"); | |
put("16","Gharbia"); put("17","Monufia"); put("18","Beheira"); put("19","Ismailia"); put("21","Giza"); put("22","Bani Suef"); put("23","Fayum"); put("24","Menya"); put("25","Asuit"); | |
put("27","Qena"); put("28","Aswan"); put("29","Luxor"); put("31","Red Sea"); put("32","Alwady Algaded"); put("33","Matrouh"); put("34","North Sinai"); put("35","South Sinai"); put("88","N/A"); | |
} | |
}; | |
public static void main(String[] args) { | |
// 01234567891234 | |
String ID_input = "30502211325055"; // National ID | |
// [3] -> 2000-2099 , YY,MM,DD , GovID , Birth ID , Checksum | |
// 3 , 05 02 21 , 13 , 2505 , 5 | |
System.out.println(getBirthYear(ID_input)); | |
System.out.println(getGov(ID_input)); | |
System.out.println(getGender(ID_input)); | |
} | |
/* | |
* Get Gender from National ID | |
*/ | |
static String getGender(String in) { | |
String out = ""; | |
int indicator = Integer.parseInt(in.substring(12, 13)); | |
if(indicator % 2 == 0) { | |
out = "Female"; | |
} | |
else { | |
out = "Male"; | |
} | |
return out; | |
} | |
/* | |
* Get Gov. from National ID | |
*/ | |
static String getGov(String in) { | |
String out = ""; | |
String GovID = in.substring(7,9); // 13 | |
out = GovIDMap.get(GovID); | |
return out; | |
} | |
/* | |
* Gets Birth Year from National ID | |
*/ | |
static String getBirthYear(String in) { | |
String out = ""; | |
String Sec_1 = String.valueOf( | |
17+ | |
Integer.valueOf( | |
in.substring(0, 1))); // 20 | |
String Sec_2 = in.substring(1,3); // 05 | |
out = Sec_1 + Sec_2; | |
return out; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment