Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Java in General
Validating IQAMA number - Java Source code
Abhi Bose
Greenhorn
Posts: 3
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Function to validate the Saudi IQAMA number.
Abhi Bose
Greenhorn
Posts: 3
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
private int findBlockLength(String iqama, int position) { int temp_length =Integer.parseInt(iqama.substring( position,position+1) ) * 2;// ((iqama.substring(position) * 2)); int retVal = Integer.toString(temp_length).length(); return retVal; } private int evaluateBlock(int blockValue, String iqama,int position ) { //Get the char from the position in the iqama number int trimValue = Integer.parseInt(iqama.substring(position,position + 1)); //based on the block length value, the logic needs to be performed if(blockValue == 1){ return trimValue * 2; }else if(blockValue == 2) { //89 // 8*2 = 16 ; 1 //firstplace = 1 //SecndPlace = 6 // int sum = trimValue *2; int firstPlace = Integer.parseInt((Integer.toString(sum)).substring(0, 1)); int secondPlace = 0 ; if (Integer.toString(sum).length() >1) { secondPlace = Integer.parseInt((Integer.toString(sum)).substring(1, 2)); } return (firstPlace + secondPlace); } return 0; } /** * Method to validate the Iquama number. * * @param id * @return */ public boolean validateIqamaNo(String id) { int l = id.length(); if(l != 10){ return false; } int s =Integer.parseInt(id.substring(1,2)) + Integer.parseInt(id.substring(3,4)) + Integer.parseInt(id.substring(5,6)) + Integer.parseInt(id.substring(7,8)) ; //---------------first block ----------- int temp_s1 = 0; temp_s1 = evaluateBlock(findBlockLength(id,0),id,0); s = s + temp_s1; //-----------------second block ------------- int temp_s2 = 0; temp_s2 = evaluateBlock(findBlockLength(id,2),id,2); s = s + temp_s2; //-----------------third block ------------- int temp_s3 = 0; temp_s3 = evaluateBlock(findBlockLength(id,4),id,4); s = s + temp_s3; //-----------------forth block ------------- int temp_s4 = 0; temp_s4 = evaluateBlock(findBlockLength(id,6),id,6); s = s + temp_s4; //-----------------fifth block ------------- int temp_s5 = 0; temp_s5 = evaluateBlock(findBlockLength(id,8),id,8); s = s + temp_s5; // Remainder of s over 10 ..... modullus int r = (10 - (s % 10)); if(r == 10){ r = 0; } int temp_s6 = Integer.parseInt(id.substring(9,10)); if(temp_s6 == r){ return true; }else{ return false; } }
Martijn Verburg
author
Posts: 3285
13
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi there,
I'm not sure what the question is?
Cheers, Martijn,
Twitter
.
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
substring to just get the last character
B&S: code complexity and number of classes
Generic Question
Java String & int
Validating Comma Separated Values
More...