Java Code for Validating 13 Digit ISBN Codes

by Paul Wilson


Often this is exactly what I feel Java is!

So, I know that this isn’t a marketing post, but when you eat, breathe, and drink computer programming you tend to also write about it as well. Currently, for my master’s program I am enrolled in a Java programming class. As stated in previous posts, Java hasn’t been easy for me to learn. I am a hard core marketing guy. However, I do see great value in being able to speak geek language. It probably isn’t efficient any more for me to tell programmers to wave their magic keyboard and build what I am dreaming up in my head.

With that being said I am going to post the java projects that are either a) really cool or b) projects that I am just dang proud of completing. This project falls into the later category. The project is not all that interesting, unless you are someone who wants to validate ISBN codes for fun. Didn’t think so!

For this project my professor wanted us to build a program which calculates the 12 digits of an ISBN code and provide the 13 digit for validation. I didn’t know this, but ISBN codes are setup in a way for you to check if they are valid. To do this you have to follow this equation (you can also see the equation below.

Yeah, the equation didn’t really make sense initially to me either. Yet, when you feel your academic life hangs upon understanding it you learn real quick exactly what the equation is saying. In none geek speak, the equation states you must add the first 12 numbers, divide them by eleven, and take the remainder for your answer. Once you have an answer you can see if the ISBN is valid by matching it with the 13th number on the ISBN code.

An example would be using the ISBN code of my Java text Book, which is 978-0132222204. To find out if the the ISBN is valid the answer to the above equation would have to be 4, since that is the last number of the ISBN code. Again, not reviting stuff, but I worked hard in coming up with the right code to do this. Below is my java code, for all those crazy ISBN geeks who will appreciate it! Maybe some day after I have mastered Java I will make a web interface for it (but I am certain there is already something out there).

Anyway, thanks for letting me show off my first java child. I am such a proud parent =).



Related Posts: