Question: Implement the luhn algorithm in java. Sample output should be like this. Please try to use one class only. Thank you! 1. From the right-to-left,
Implement the luhn algorithm in java. Sample output should be like this. Please try to use one class only. Thank you!


1. From the right-to-left, double the value of each digit that is in an even-numbered position (with the check-digit at position 1). If this doubling gives you a two-digit value for any of the numbers, then subtract 9 from the value (which is easier than adding the digits together but gets you the same result). Leave the odd-valued positions as is. 2. Sum together all of the values except the check digit. 3. Take the digit in the one's position of the sum. If the value of that digit is, then it stays as 0. If the value is greater than zero, subtract that value from 10. That value should be the check digit (note that the special case for O is required since "10" is not a single digit). Sample Output: This is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen by your program. Enter a credit card number (enter a blank line to quit): 5457623898234112 Check digit should be: 3 Check digit is: 2 Number is not valid. Enter a credit card number (enter a blank line to quit): 5457623898234113 Check digit should be: 3 Check digit is: 3 Number is valid. Enter a credit card number (enter a blank line to quit): 5555555555554 ERROR! Number MUST have exactly 16 digits. Enter a credit card number (enter a blank line to quit): 5555555555554445 Check digit should be: 4 Check digit is: 5 Number is not valid. Enter a credit card number (enter a blank line to quit): Goodbye! Note: You will need to convert characters in your string into integer values to make this project work. There are two ways to do this. The first is to use Integer.parseInt and substring to get a character value. The following lines of code would give you the integer value of the first character of the string input
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
