Question
Print appropriate messages to let the user know if the card is valid or not valid. Use of the Random class is required, and you
Print appropriate messages to let the user know if the card is valid or not valid.
Use of the Random class is required, and you may not use arrays.
You may find the following comments helpful to guide your work:
set up a Scanner, set up a boolean named validCreditCard and set it to false
loop while not a valid credit card , prompt the user for a potential credit card number
Get the credit card number as a String - store in potentialCCN (use scanner's nextLine)
use Luhn to validate credit card using the following steps:
store the digit AS AN INT for later use in lastDigit (probably requires Integer.parseInt(String)
TEST then comment out! - check the last digit - System.out.println(lastDigit);
remove the last digit from potentialCCN and store in potentialCCN using String's substring
TEST then comment out! - check potentialCCN - System.out.println(potentialCCN);
create reversedCCN as a empty String
reverse the digits using a for loop by adding characters to reversedCCN
TEST then comment out! - check reversedCCN - System.out.println(reversedCCN);
set boolean isOddDigit to false, set up an integer called current digit and set it to , create an integer named sum and set it to 0
multiply the digits in odd positions by 2, then subtract 9 from any number higher than 9 using:
(for loop running 0 to less than length of reversed CCN), set currentDigit equal to the integer version of the current character
Test then comment out! - currentDigit -System.out.print(currentDigit), toggle isOddDigit
if isOddDigit, multiply currentDigit by 2 and store in currentDigit
if currentDigit > 9, subtract 9 from currentDigit and store in currentDigit
TEST then comment out - Check currentDigit - System.out.println(currentDigit);
end if isOddDigit
Comment in this segment for a useful test output string, System.out.print(currentDigit);
if (i>=reversedCCN.length()- ,System.out.println()
else System.out.print(" + "); end of segment, add currentDigit to sum and store in sum
end reverse the string
TEST and comment out - System.out.println("sum:"+sum);
if the last digit of sum is equal to lastDigit, set isValidCreditCard to true
if validCreditCard is false, output an appropriate message
end while that checks for valid credit card ,issue a RANDOM PIN and print it out - no more help
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