(Financial: Credit card number validation) Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits. It must start with
In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine whether a card number is entered correctly or whether a credit card is scanned correctly by a scanner. 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 4388576018402626.
Write a program that prompts the user to enter a credit card number as a long integer. Display whether the number is valid or invalid. Design your program to use the following methods:
/** Return true if the card number is valid */
Public static Boolean isValid(long number)
/**Get the result from Step 2 */
Public static int sumOfDoubleEvenPlace(long number)
/**Return this number if it is a single digist, otherwise, return the sum of the two digits*/
Public static int getDigit(int number)
/**Return sum of odd-place digits in number */
Public static int sumOfOddPlace(long number)
/**Return true if the digit d is a prefix for number */
Public static int getSize(long d)
/**Return the number of digits in d */
Pubic static int getSize(long d)
/**Return the first k number of digits from number. If the number of digits in number is less than k, return number. */
Public static long getPrefix(long number, int k)
Credit Card Number Validation: Complete program 6.31 with the following enhancements:
The program should allow the user to input more than one credit card number in a session (handled one at a time). For example, the user can be asked whether they want to continue and yes or no response can be processed or you can use a sentinal input value. Your program should be clear in directing the user on how the program will handle multiple inputs.
The program should have additional output when the user exits the program. This additional output will be the following statistics: