Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Banks issue credit cards with 16 digit numbers. If you've never thought about it before you may not realize it, but there are specific rules

Banks issue credit cards with 16 digit numbers. If you've never thought about it before you may not realize it, but there are specific rules for what those numbers can be. For example, the first few digits of the number tell you what kind of card it is - all Visa cards start with 4, MasterCard numbers start with 51 through 55, American Express starts with 34 or 37, etc. Automated systems can use this number to tell which company to contact without having to "look" at the card itself and see what the bank is on it.

Another key part of the credit card number standard is the check digit . The last digit of every credit card number is determined by the previous 15 digits through a simple mathematical formula known the Luhn Algorithm. The Lhun Algorithm can be used to check if a credit card number has been corrupted in its transmission between the vendor reading the card, and the bank which has the account. It can also be used to check to see if a credit card number is valid before transmitting it to the bank.

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

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.

Sum together all of the values except the check digit .

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).

Required:

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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

File Name Project06java Import files import javautil Create class public class Project06 Define func... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Document Format ( 2 attachments)

PDF file Icon
60942cb41e896_24564.pdf

180 KBs PDF File

Word file Icon
60942cb41e896_24564.docx

120 KBs Word File

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Ethics in Accounting A Decision Making Approach

Authors: Gordon Klein

1st edition

1118928334, 978-1118928332

More Books

Students also viewed these Programming questions

Question

What does stickiest refer to in regard to social media

Answered: 1 week ago

Question

3. Explain analytic deduction.

Answered: 1 week ago

Question

4. Explain the five-component model for quantitative research.

Answered: 1 week ago