CSC 321: Data Structures
Spring 2024

HW1: Credit Card Verification


According to the 2022 TransUnion Credit Industry Insight Report, there were more than 166 million credit card users in the U.S. at the end of 2022, with an average of three cards per user. While credit cards have become the preferred method of payment for American consumers, few ever wonder about the random-seeming sequence of digits on the front. In fact, these digits are far from random. Visa, Mastercard and Discover all utilize a 16-digit sequence, with the first six digits identifying the card issuer and the next nine digits identifying the user's account number. American Express utilizes a 15-digit sequence, with six digits for the issuer and eight for the user account number. The remaining digit on each card serves as a check number for verifying the card's validity. This last digit is assigned according to the Luhn Formula.

PART 1: Verifying Sequences (2-person team)

For the first part of this assignment, you are to write a Java program that reads in a series of digit sequences from a file whose name is entered by the user. Your program must identify whether each is a valid credit card sequence, i.e., whether it is of the correct format according to the Luhn Formula. Your program should display each sequence on a line, followed by its classification: either VALID or INVALID. Note: there will be one digit sequence per line, and there may be spaces within the sequence (which are ignored with respect to the Luhn Formula). Any sequence that contains a character other than a digit or space is considered invalid.

For example, suppose the file specified by the user contained the following:

    4289 0298 7524 0023
    4289 0298 7524 0026
    313 4890 444 2000 120
    42 89 01 44 32 58 99 4
    42 89 01 44 32 58 99 40
    4289 0144 3258 9941
    1234-5678-9876-5432 
Then, your program should output:
    4289029875240023 VALID
    4289029875240026 INVALID
    31348904442000120 VALID
    428901443258994 VALID
    4289014432589940 INVALID
    4289014432589941 INVALID
    1234567898765432 INVALID

For Part 1, you will work in a two-person team with your partner assigned by the instructor. 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). 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.

PART 2: Organizing Output & Error Detection (independent work)

For the second part of this assignment, you are to organize the output so that all of the valid sequences are displayed together (with heading VALID), followed by all of the invalid sequences (with heading INVALID). Within each category, the sequences should be displayed in increasing numerical order (ignoring any non-digits).

You should also augment your program so that it can handle sequences in which a single digit has been corrupted. That is, the character '?' may appear in a sequence in the place of an unknown digit. Because of the check number, it should be possible to determine the value of the missing digit. Augment your program so that it determines the missing digit and adds the corresponding sequence to the list of valid sequences. Note: any code that contains more than one '?' is considered invalid.

For example, suppose the file specified by the user contained the following:

    4289 0298 7524 0023
    4289 0298 7524 0026
    313 4890 444 2000 120
    42 89 01 44 32 58 99 4
    42 89 01 44 32 58 99 40
    4289 0144 3258 9941
    1234-5678-9876-5432 
    4289 029? 7524 0023
    ?289 0298 7524 0023
    4289 0298 752? ?023
Then, your program should output:
    VALID
    31348904442000120
    428901443258994
    4289029875240023
    4289029875240023
    4289029875240023

    INVALID
    1234567898765432
    4289014432589940
    4289014432589941
    4289029875240026
    42890298752??023

Part 2 must be completed individually (with help from the instructor, as needed). You may build on the code you and your partner created for Part 1. As before, you are expected to demonstrate good programming style.