Question: Your program should be in a new project named Program 2: Credit Card Validation and should be in a package named creditCard. Your program must

Your program should be in a new project named "Program 2: Credit Card Validation" and should be in a package named "creditCard". Your program must be in a file called "Program2CCValidation". Write a Java program that will issue a 4 digit random PIN (1111 to 9999) for a credit card. The program that will verify that the credit card number is valid using the Luhn Algorithm. User will be prompted to enter their card number until a valid number is entered. A PIN will be issued only if the card is valid.

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 ( I would include them in the main method and follow them step-by-step!) :

//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 0

//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()-1)

//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 + the last Digit ends in a zero, 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

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!