Question: Please write a Java program that print as below: Validating Credit Card Numbers Write a program named Creditcard. java that prompts the user for a
Validating Credit Card Numbers Write a program named Creditcard. java that prompts the user for a credit card number and determines whether it is valid or not. Much of this assignment is taken from exercise 6.31 in the book) Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits, and must start with: -4 for Visa cards .5 for Master cards er 6 for Discover cards 37 for American Express cards The algorithm for determining whether a card number is entered correctly as developed by Hans Luhn of IBM in 1954. The Luhn check or Mod 10 check works as follows. Consider the card number 1. Double every second digit from right to left. If the doubling of a digit results in a two-digit number, add up the digits to get a single-digit number. The digits are shown in bold and italic here: 5842016792622547 This gives us (from right to left) o 2 2 4 o 6 2-12 (1+2) 3 o 9 2-18 (1+ 8)-9 o 6 2 12(12) 3 o 0 2 0 04 2-8 o 5 2-10 1+0) 1 2, Add up those numbers (8 + 4 + 3 + 9 + 3 +0+8+1#36) 3. Now add up all the digits in the odd positions from right to left: (7+5+2+2+7+1+2 +8-34) Add those two numbers (36+34-70). If this sum is divisible by 10, the number is valid. If it is not divisible by 10, the number is not valid. 4. Your program will prompt the user to enter a credit card number as a long integer and display whether the number is valid or not. Design your program to use the following methods
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
