Project: Credit Card Validator
The [[Luhn Algorithm]] is a simple checksum algorithm that is used to verify that credit card numbers are correctly entered. Using this algorithm we can easily catch most single digit errors and simple transpositions.
Write a function to verify that the last digit of a credit card is the one expected when computing a checksum digit using the Luhn Algorithm. The function should take a credit card number as a string of 16 digits (no spaces) and return true or false if the last digit matches the computed checksum. Test the program with your own credit card numbers or the samples below.
Output
$ javac -Xlint CreditCardValidator.java
$ java -ea CreditCardValidator
Good Test Cases
4321123456789019 is true
5432123456789020 is true
65432101234567896 is true
Bad Test Cases
4321123456798019 is false
4432123456789020 is false
65431201234567896 is false