Credit Card Number Verification Program:
This program simulates the process of credit card number verification. However, note that the algorithm mentioned here is NOT the exact same algorithm companies use. First, your program should ask if the credit card is a MasterCard or Visa card. Then ask for the 16-digit credit card number. Then add all the digits in the credit card number and get the modulo 10 of the sum. If the modulo 10 of the summation of all the digits is zero, then it's a valid Visa card. If the modulo 10 of the summation of all the digits is 1, then it's a valid MasterCard. Otherwise, the number the customer has entered is an invalid card number.
For example, say the card number is 1234567867891235 and the card type entered is Visa. To validate it, first add all the digits:
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 6 + 7 + 8 + 9 + 1 + 2 + 3 + 5 = 77
Then get mod 10 of 77:
(77 % 10 = 7)
Since it's not zero, this is not a valid Visa card number.
Write a Java program that reads the card type and the card number and then determines if the card number entered is valid.
Save your program as Assignment2.java
Requirements and input validation:
Card Number:
You need to read the card number as a long int. The card number should have 16 digits. If the card number does not have 16 digits, then ask the user to re-enter the number.
Card Type:
Card type must be entered as Visa or Master. If the user enters any other type, then ask the user to re-enter the card type.
Sample Input and Expected System Output:
Run 1:
Enter the card number: 1111111111000000
Enter the card type: Visa
This is a valid Visa card
Run 2:
Enter the card number: 1111111111100000
Enter the card type: Master
This is a valid Master card
Run 3:
Enter the card number: 1111111111110000
Enter the card type: Master
This is not a valid Master card
Run 4:
Enter the card number: 1111111111110000
Card number should have 16 digits, re-enter
Enter the card number: 1111222211112200
Enter the card type: Master
This is not a valid Master card
Run 5:
Enter the card number: 1111222211112200
Enter the card type: Amex
Invalid card type selected. Please select Visa or Master.
Enter the card type: Visa
This is a valid Visa card