Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a java program that reads from a list of credit cards and determines if those cards are valid. Each file provided encodes the credit
Write a java program that reads from a list of credit cards and determines if those cards are valid. Each file provided encodes the credit card numbers are longs. In binary, read each long and process the card.
To determine if a credit card is valid, use the following algorithm.
- From the rightmost digit, which is the check digit, and moving left, double the value of every second digit. The check digit is not doubled; the first digit doubled is immediately to the left of the check digit. If the result of this doubling operation is greater than 9 (e.g., 8 2 = 16), then add the digits of the result (e.g., 16: 1 + 6 = 7, 18: 1 + 8 = 9) or, alternatively, the same final result can be found by subtracting 9 from that result (e.g., 16: 16 9 = 7, 18: 18 9 = 9).
- Take the sum of all the digits. (Display this to the user)
- If the total modulo 10 is equal to 0 (if the total ends in zero) then the number is valid.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started