The International Standard Book Number (ISBN) is a code assigned to a published book to uniquely identify that book. The current standard for ISBN, which was adopted in 2007, utilizes a 13-digit format with optional dashes to provide structure. For example, the ISBN code for your textbook, Introduction to the Design and Analysis of Algorithms (2nd ed.), is 978-03-2135-828-8.
To facilitate error checking when processing ISBN codes, the last digit in an ISBN code is a check digit that is based on the preceding 12 digits. For example, let us represent a 13-digit ISBN code as the sequence x1x2...x13
. The value of the check digit x13
is calculated as:
x13 = (10 - ((x1 + 3x2 + x3 + 3x4 + ... + x11 + 3x12) % 10)) % 10
For the first part of this assignment, you are to write a Java program that reads in a series of ISBN codes from a file (whose name is entered by the user). Your program must identify whether each code is valid, i.e., it is of the correct format and the check digit is correct. After all of the codes have been processed, your program should display all of the valid codes (with the heading VALID), followed by a blank line, followed by all of the invalid codes (with the heading INVALID). Within each category, the codes should be displayed in increasing lexicographical order (ignoring any dashes).
For example, suppose the file specified by the user contained the following:
978-04-2135-828-8 978-03-2135-828-8 97A-03-2135-828-8 978-1408819899 978-0-13-216675-1 978-0-13-601722-6Then, your program should output:
VALID 978-0-13-216675-1 978-0-13-601722-6 978-03-2135-828-8 INVALID 978-04-2135-828-8 978-1408819899 97A-03-2135-828-8
For the second part of this assignment, you are to augment your program so that it can handle codes in which a single digit has been corrupted. That is, the character '?' may appear in a code in the place of an unknown digit. Because of the check digit, it is possible to determine the value of the missing digit. Augment your program so that it determines the missing digit and adds the corresponding ISBN code to the list of valid codes.
For example, suppose the file specified by the user contained the following:
978-04-2135-828-8 978-03-2135-?28-8 97A-03-2135-828-8 978-140881989? 978-0-13-216675-1 978-0-13-601722-6Then, your program should output:
VALID 978-0-13-216675-1 978-0-13-601722-6 978-03-2135-828-8 978-1408819890 INVALID 97A-03-2135-828-8 978-04-2135-828-8
You must demonstrate good programming style when completing this assignment, including the appropriate use of Javadoc-style comments for all classes and methods. The interface for your program is entirely up to you. It need not be fancy, but it must at least allow the user to enter a file name and view the results. You may choose to use the GUI builder that comes with NetBeans if you wish.