This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ID number errors

 
Nicholas Lefebvre
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After doing some research regarding South African ID numbers, you discover the following facts.
1. All numbers are 13 digits long.
2. The first 6 digits indicate the person's year, month and day of birth – yymmdd.
3. The next 4 digits indicate gender.
0000 to 4999 is used for male
5000 to 9999 is used for female
We can therefore summarise that, if the number in position 7 is greater or equal to 5 the person is female, otherwise the person is male.
4. The last number is a control digit to verify the number when a mathematical formula is applied. Here is a brief summary of the way this works:

I am getting errors and i need some help please.



my code is below

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nicholas Lefebvre wrote:I am getting errors and i need some help please.

What are the errors you get?

Please TellTheDetails (<= click on that).
 
Unnar Björnsson
Ranch Hand
Posts: 164
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems that you check the input string for length, which is good but all you do is print out whether the strign is of the correct length or not. If the string is shorter than 13 you'll get StringIndexOutOfBoundsException
 
Nicholas Lefebvre
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what i get when i run the script:
run:
13
The ID Number Is The Correct Lenght
12
1134256
2013/03/19 : 09/03
Exception in thread "main" java.lang.NumberFormatException: For input string: "2013/03/19 : 09/03"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at Sba.main(Sba.java:85)
Java Result: 1
BUILD SUCCESSFUL (total time: 33 seconds)
 
Nicholas Lefebvre
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the formual used to verfy the id number:

Values if the ID number 5506075122086 is used

Add all the digits in odd positions except the digit in position 13.
TotalA = Digit1 + Digit3 + Digit5 + Digit7 + Digit9 + Digit11
TotalA = 5 + 0 + 0 + 5 + 2 + 0 = 12
TotalB = Concatenate all the digits in even positions. TotalB = 567128
TotalB = TotalB x 2 TotalB = 567128 x 2 = 1134256
TotalC = Add all the digits in TotalB TotalC = 1 + 1 + 3 + 4 + 2 + 5 + 6 =22
TotalD = TotalA + TotalC TotalD = 12 + 22 = 34
ControlNumber = 10 – the last digit of TotalD
(If the last digit of TotalD is 0, the ControlNumber becomes 0.) ControlNumber = 10 – 4 = 6
Compare the calculated ControlNumber to the control digit of the ID number. ControlNumber = control digit (last digit) of ID number. Therefore it is a valid ID number.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at this part of your code.

What's happening here: You first format a date using the format "yyyy/MM/dd : HH/MM". The result is a string that looks like this: "2013/03/19 : 09/03"

Then you try to parse that string as if it is an integer (to get the year). But "2013/03/19 : 09/03" is ofcourse not a valid integer.

So, don't try to parse "2013/03/19 : 09/03" as if it is an integer. Do something else instead. Do you need to get the year? Use java.util.Calendar for that:

 
Winston Gutkowski
Bartender
Pie
Posts: 9488
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:You first format a date using the format "yyyy/MM/dd : HH/MM"...

@Nicholas: And the simple fact is that you can't convert all ID's to dates because you only have a 2-digit year.

It's relatively easy to work out that "550607" is 1955/06/07, but what about "100607" - is that 2010/06/07 or 1910/06/07?

I seem to remember that South Africa held the record for the world's oldest living person for a short while.

Winston
 
Nicholas Lefebvre
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok i got the date from the pc.
But with what your are saying about the 2 digit year what should i do.
 
Winston Gutkowski
Bartender
Pie
Posts: 9488
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nicholas Lefebvre wrote:But with what your are saying about the 2 digit year what should i do.

Well, if this really is a proper South African ID number, I'd find out what the government does.

Alternatively, you could use the current year (ie, 13 right now), and subtract 1 from the current century (20) if the yy field is greater than it; however, it's a bit of a kludge.

BTW, typical example of a government code designed by idiots (indeed, probably by a committee of them).

Winston

PS: Please DontWriteLongLines. I've tried to break yours up as best I can, but it makes your Thread very hard to read.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic