java financial credit card number validation credit card numbers follows certain pat 4949199
Java
Financial: Credit card number validation.
Credit card numbers follows certain patterns. A creditcard number must have between 13 and 16 digits. It must startwith:
4 for Visa cards
5 for Master cards
37 for American Express cards
6 for Discover cards
In 1954, Habs Luhn of IBM proposed an algorithmfor validating credit card numbers. The algorithm is useful todetermine whether a card number is entered correctly or whether acredit card is scanned correctly by a scanner. Credit card numbersare generated following this validity check, commonly known as theLuhn check or Mod 10 check, which is described as follows( for illustration, consider the card number4388576018402626):
Double every second digit from right to left. If doubleof a digit results in a two-digit number, add up the two digits toget a single digit number.
Now add all single-digit number from the step above(Step 1 ).
4 + 4 + 8 + 2 + 3 + 1 + 7 + 8 =37
Add all digits in the odd places from right to left inthe card number.
6 + 6 + 0 + 8 + 0 + 7 + 8 + 3 = 38
Sum the results from the above two step ( Step 2 andStep 3).
37 + 38 = 75
If the result from the above step ( step 4 ) isdivisible by 10, the card is valid; otherwise, the card is invalid.For example, the card number 4388576018402626 is invalid, but thecard number 4388576018410707 is valid.
Design and Implement the above algorithm in JavaRecursively. Your algorithm should prompt the user toenter a credit card number as a long integer. Display whether thenumber is a valid or invalid credit card number. Design yourprogram to use the following methods: These methods should be donerecursively… Make sure you have several runs, i.e. several testingconditions.
//Return if the card number is valid
P
ublic static Boolean isValid(longnumber)
//Get the result from step 2
P
ublic static int sumOfDoubleEvenPlace(long number )
//Return this number it is a single digit, otherwise,return the sum of the two //digits
P
ublic static int getDigit( int number)
//Return sum of sumOfOddPlace( long number)
P
ublic static int sumOfOddPlace( longnumber )
//Return the number of digits in digit
P
ublic static int getSize( long number)
//Return the first k number of digits from the number.If the number of digits in number is less than k, returnnumber
P
ublic static long getPrefix( longnumber, int k )
Here are some runs of the program
Enter a credit card number as a longinteger
4388576018410707
4388576018410707 is a valid credit cardnumber.
Enter a credit card number as a longinteger
4388576018402626
4388576018402626 is a valid credit cardnumber. . . .