* credit card numbers and determines of the * Class ProcessCardNumbers reads a text file of * A boolean value of true if the card number is valid, * should be divisible by 10 with no remainder. * If the card is valid, the total of sumEverySecondDigitRightToLeft() * The method determines if the credit card number is valid. Public int sumOfOddPlaceDigitsRightToLeft() * in the credit card string is counted as the first position. * credit card string, going from right to left, where the last number * The method calculates the sum of the digits in the odd positions of the Public int sumEverySecondDigitRightToLeft() * An integer which is the sum of the digits.
* number, add up the two digit to get a single digit number and add to the total. * If doubling of a digit results in a two-digit * This method returns the total of doubling every second digit from right to left. * or the sum of the two digits of the double digit parameter
* An integer, either the single digit number parameter * number A single or double digit integer * return the sum of the two digits in the number parameter * If it is a single digit number, return that number, otherwise * Determines whether the number parameter is a single or double digit number. * or the string "Unknown" if the type cannot be found. * The credit card type, either "Visa", "MasterCard", "American Express", or "Discover" * determines if the card type is either "Visa", "MasterCard", "American Express", or "Discover" * Using the leading digits and the length of the card number, this method Public void setCardNumber(String cardNumber) * A string that is the credit card number * Accessor method to return the cardNumber * cardNumber A credit card number used to initialize the field * Constructor for objects of class CreditCard. If the result from Step 4 is divisible by 10, the card number is valid otherwise, it is invalid. Now add all the single digit numbers from Step 1.Īdd all digits in the odd places from right to left in the card number. If doubling of a digit results in a two-digit number, add up the two digits to get a single-digit number.
#EXAMPLE BLUEJ PROGRAM CREDIT CARD MOD#
Almost all credit card numbers are generated following this validity check, commonly known as the Luhn check or the Mod 10 check, which can be described as follows (for illustration, consider the card number 4388576018402625):ĭouble every second digit from right to left.
The algorithm is useful to determine if a card number is entered correctly or if a credit card is scanned correctly by a scanner. In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. Master cards – length 16, must start with 51 - 55Īmerican Express cards – length 15, must start with 34 or 37ĭiscover cards – length 16, must start with 6011 Visa cards – length 13 or 16, must start with 4, The example below shows the output from calling the validateCreditCardNumbers main method.Ĭredit card numbers follow certain patterns for length and starting digits:
#EXAMPLE BLUEJ PROGRAM CREDIT CARD CODE#
Read the comments in the source code of the validateCreditCardNumbers project and finish writing the classes according to those instructions. An explanation of the validation algorithm can be found in the document Credit Card Validation.docx. The validateCreditCardNumbers project reads a list of credit card numbers from a text file and uses the Luhn check to determine if the card numbers are valid.