Lunch Check

Credit Card Validation Assignment

It is possible to tell if a number could be a valid credit card. All credit cards numbers can be validated agains an algorithm known as a Luhn
check.
The Luhn Check:
  • Counting from the check digit, which is the rightmost, and moving left, double the value of every second digit.
  • Sum the digits of the products together with the undoubled digits from the original number.
  • If the total ends in 0 (put another way, if the total modulo 10 is congruent to 0), then the number is valid according to the Luhn formula; else it is not valid.
  • As an illustration, if the account number is 49927398716, it will be validated as follows:

    1. Double every second digit, from the rightmost: (1 × 2) = 2, (8×2) = 16, (3×2) = 6, (2×2) = 4, (9×2) = 18
    2. Sum all the individual digits (digits in parentheses are the products from Step 1): 6 + (2) + 7 + (1+6) + 9 + (6) + 7 + (4) + 9 + (1+8) + 4 = 70
    3. Take the sum modulo 10: 70 mod 10 = 0; the account number is valid.
    4. Mod 10+5 Variant Some credit cards use the "Mod 10 plus 5" variant to extend the space of valid card numbers.[citation needed] In this variant, if the sum ends in 0 or 5, the number is considered valid

    The Assignment

    Write a class whose
  • has an instance variable called cardNum and a boolean variable called isMod5Varient
  • constructor takes two parameters:
  • the following methods:
  • site map | resources