Tuesday, September 1, 2009

Homework 1: ISBN check digits

Every book has an ISBN number. It is that number you see just above the bar code. For example, our textbook has an ISBN of 013607225-9. The dashes are not important, only the numbers matter.

Most importantly, the last number, known as a check digit, is computed from the first 10 digits using a specific equation. The wikipedia explains how:

A check digit is a form of redundancy check used for error detection, the decimal equivalent of a binary checksum. It consists of a single digit computed from the other digits in the message.

ISBN-10

The 2001 edition of the official manual of the International ISBN Agency says that the ISBN-10 check digit — which is the last digit of the ten-digit ISBN — must range from 0 to 10 (the symbol X is used instead of 10) and must be such that the sum of all the ten digits, each multiplied by the integer weight, descending from 10 to 1, is a multiple of the number 11. Modular arithmetic is convenient for calculating the check digit using modulus 11. Each of the first nine digits of the ten-digit ISBN — excluding the check digit, itself — is multiplied by a number in a sequence from 10 to 2, and the remainder of the sum, with respect to 11, is computed. The resulting remainder, plus the check digit, must equal 11; therefore, the check digit is 11 minus the remainder of the sum of the products.

For example, the check digit for an ISBN-10 of 0-306-40615-? is calculated as follows:

s = 0×10 + 3×9 + 0×8 + 6×7 + 4×6 + 0×5 + 6×4 + 1×3 + 5×2
  =    0 +  27 +   0 +  42 +  24 +   0 +  24 +   3 +  10
  = 130
130 / 11 = 11 remainder 9
11 - 9 = 2
Thus, the check digit is 2, and the complete sequence is ISBN 0-306-40615-2.

Formally, the check digit calculation is:
If the result is 11, a '0' should be substituted; if 10, an 'X' should be used.

The two most common errors in handling an ISBN (e.g., typing or writing it) are an altered digit or the transposition of adjacent digits. Since 11 is a prime number, the ISBN check digit method ensures that these two errors will always be detected. However, if the error occurs in the publishing house and goes undetected, the book will be issued with an invalid ISBN.

For this homework you will write a program which asks the users for the first 9 digits of the ISBN-10 number and then calculates and prints out the last digit. As such:

Enter 9-digit number: 0-13-607225
The last digit is 9
or
Enter 9-digit number: 013607225
The last digit is 9

Notice that your program must work even if the user enters the number with dashes, which he can place anywhere he wants.

The program is due by Tuesday, Sept. 8 @noon. When you are finished simply email the .java file to your TA, make sure you type CSCE145 in the Subject: line of your email. You should also cc: me in that email. The email must be sent by the deadline or you will not receive credit.

Finally, remember that you are bound by our Honor Code. Please, be responsible for your own work.

3 comments:

Anonymous said...

Shouldn't we be asking for 9 digits and our program provides the tenth as the examples have 9 digits being imputed by the user.

jmvidal said...

Yes, you are correct. I'll fix the handout. Thanks!

jmvidal said...

Someone pointed out that I got the ISBN number wrong in the example. I've just fixed it. In case you're wondering, its the ISBN of our textbook.