Question: Write a program that will generate a set of valid credit card numbers for a particular bank. Step 1: Prompt the user to enter their
Write a program that will generate a set of valid credit card numbers for a particular bank.
Step 1: Prompt the user to enter their 4-digit bank identifier. The user will then be
prompted to specify the quantity of valid 16-digit credit card numbers that they would like generated.
Input is as follows:
Enter the first four digits of credit card numbers:
Enter quantity of credit card numbers to generate:
If a user enters an invalid value, the program should notify the user that the value entered is incorrect,
and why, and prompt the user to reenter a corrected value.
Step 2:
The program will randomly generate the quantity of credit card numbers specified
by the user, with the first 4 digits being those provided by the user.
To generate a valid number, we will need to
1. Randomly generate the number
2. Test the number generated to make sure that it adheres to the correct credit card format
3. If the number fails the test, we will need to continue to generate another random number until
we find one that satisfies the required format.
BREAK THE CREDIT CARD NUMBER INTO SMALLER PIECES (e.g., 4 numbers of 4 digits, rather
than 1 number of 16 digits).
- The calculations needed to test the generated number can performed on the smaller pieces and
then added together to get the calculation on the full 16 digit credit card number.
- Note: the calculations on the first 4 digits only needs to be calculated once, since it will be the same for every credit card number that we generate.
1. TO RANDOMLY GENERATE THE NUMBER
USE THE FORMULA TO GENERATE A RANDOM NUMBER:
min + (int)(Math.random() * ((max - min) + 1))
2. TO TEST THE NUMBER GENERATED
A credit card number is valid if step 4 in the following check is confirmed:
1. Form the sum of all digits.
2. The result is divisible by 10.
Step 3: Output. The program will print out the valid credit card numbers generated
Valid Credit Card Numbers Generated:
4212346231729310
4212967811827381
4212448847490724
4212764281824108
4212110033271698
4212151546052688
4212740737468230
4212493897910362
4212007218859722
4212968498084285
When printing our generated number, we need to be sure to print any leading zeros. For example, if our
generated number is broken down into the following 4 numbers of 4 digits:
4012
689
4202
35
These need to be printed with leading zeros for the 2nd and 4th number:
4012068942020035
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
