CSC 321: Data Structures
Fall 2015

HW1: ISBN Numbers


For this assignment, you will work in a two-person team (with partner assigned by the instructor) to complete a multi-part program. The purpose of this assignment is to refamiliarize you with Java programming and identify any holes in your knowledge/skills. You may not consult with classmates or persons outside your team (other than the instructor, of course).

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 CSC121 textbook, A Balanced Introduction to Computer Science (3rd ed.), is 978-0-13-216675-1.

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

PART 1: Classifying Codes (60%)

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. Your program should display each code on a line, followed by its classification: either VALID or INVALID. Note: any code that contains a character other than a digit or dash is considered invalid.

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-6
Then, your program should output:
    978-04-2135-828-8 INVALID
    978-03-2135-828-8 VALID
    97A-03-2135-828-8 INVALID
    978-1408819899 INVALID
    978-0-13-216675-1 VALID
    978-0-13-601722-6 VALID

PART 2: Organizing Output (20%)

For the second part of this assignment, you are to organize the output so that all of the valid codes are displayed together (with heading VALID), followed by all of the invalid codes (with HEADING INVALID). Within each category, the codes should be displayed in increasing lexicographical order (ignoring any dashes). The example above would be result in the following 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

PART 3: Error Correction (20%)

For the third 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. Note: any code that contains more than one '?' is considered invalid.

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
    979-140881989?
    979-?40881989?
    978-0-13-216675-1
    978-0-13-601722-6
Then, your program should output:
    VALID
    978-0-13-216675-1
    978-0-13-601722-6
    978-03-2135-828-8
    979-1408819899
    
    INVALID
    978-04-2135-828-8
    979-?40881989?
    97A-03-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.