Help coderanch get a
new server
by contributing to the fundraiser
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:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# ID number errors

Greenhorn
Posts: 23
• Number of slices to send:
Optional 'thank-you' note:
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

Java Cowboy
Posts: 16084
88
• Number of slices to send:
Optional 'thank-you' note:

Nicholas Lefebvre wrote:I am getting errors and i need some help please.

What are the errors you get?

Please TellTheDetails (<= click on that).

Ranch Hand
Posts: 164
• Number of slices to send:
Optional 'thank-you' note:
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
• Number of slices to send:
Optional 'thank-you' note:
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
• Number of slices to send:
Optional 'thank-you' note:
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
Posts: 16084
88
• Number of slices to send:
Optional 'thank-you' note:
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:

Bartender
Posts: 10780
71
• Number of slices to send:
Optional 'thank-you' note:

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
• Number of slices to send:
Optional 'thank-you' note:
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
Posts: 10780
71
• Number of slices to send:
Optional 'thank-you' note:

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