CSC 321: Data Structures Fall 2018 HW1: Credit Card Verification

According to the American Banking Association, there were 364 million open credit card accounts in the U.S. by the end of 2017. 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, which is nicely described in this page from creditcards.com.

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
```
```    4289 0298 7524 0023 VALID
4289 0298 7524 0026 INVALID
313 4890 444 2000 120 VALID
42 89 01 44 32 58 99 4 VALID
42 89 01 44 32 58 99 40 INVALID
4289 0144 3258 9941 INVALID
1234-5678-9876-5432 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. You may choose to use the GUI builder that comes with NetBeans if you wish.

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 0298 7524 002?
4289 0298 ?524 0026
4289 0298 ?524 002?
```
```    VALID
313 4890 444 2000 120
42 89 01 44 32 58 99 4
4289 0298 1524 0026
4289 0298 7524 0023
4289 0298 7524 0023

INVALID
1234-5678-9876-5432
42 89 01 44 32 58 99 40
4289 0144 3258 9941
4289 0298 7524 0026
4289 0298 ?524 002?
```

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.