Question: Having trouble with this project The Luhn Algorithm is described at the link above, but the basic idea is: From the right-to-left, double the value

Having trouble with this project

The Luhn Algorithm is described at the link above, but the basic idea is:

  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 add the digits together to get a single digit (or equivalently, subtract 9 from the value). 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 0, then it stays as 0. If the value is greater than zoer, subtract that value from 10. That value should be the check digit (note that the special case for 0 is required since "10" is not a single digit).

For example, suppose the card you want to validate is: 5457623898234113. In this case the check-digit is 3 and the remaining digits are the 15-digit account number. We can confirm that we likely have a good card number by validating the check digit as follows:

For this lab you will write a Java program that checks credit card strings to see if they are valid. Your program should first prompt the user to enter a string of numbers as a credit card number, or enter a blank line to quit the program. If the user doesn't quit, your program should ensure that this string is exactly 16 characters in length. If the user enters a string that is not 16 characters in length, your program should print an error message and ask again for a valid string. Your program should use the Luhn Algorithm above to compute what the check digit should be and then compare it to the actual value in the provided string and report whether the credit card number is valid or wrong. If it is wrong, your program should report what the correct check digit should be for the input value. Your program should keep asking for new values until the user enters a blank line to quit the program.

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!