Tag Archives: Java Assignments

Luhn Check Assignment

Luhn Check

Luhn Check starter Code

It is possible to tell if a number could be a valid credit card. Credit cards numbers can be validated against an algorithm known as a Luhn.  Read this first.

Luhn Number Generator



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.


Image from http://www.impuls-imaging.com/wp-content/uploads/2013/07/luhn_algorithm.png

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

from http://www.moneybluebook.com/imagesvr_ce/mbb/luhn-amex-calculation.jpg


Before handing in your code, first test it with the LuhnChecker–which I will also use when grading.


A more extensive analysis with good images and an online Luhn Checker