Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Han Luhn's algorithm for validating credit card: formula is on this site: https://www.kidscodecs.com/luhn-algorithm/ Your objective is to write a program that prompts the user

Using Han Luhn's algorithm for validating credit card: formula is on this site: https://www.kidscodecs.com/luhn-algorithm/

Your objective is to write a program that prompts the user to enter a credit card number as a long integer. Display whether the number is valid or invalid. Your class name should be CreditCard and file name should be CreditCard.java Display whether the number is valid or invalid. You may also implement this program by reading the input as a string and processing the string to validate the credit card. Design your program to use the following methods:

Return true if the card number is valid: public static boolean isValid(long number)

Get the result from Step 2: public static int sumOfDoubleEvenPlace(long number)

Return this number if it is a single digit, otherwise return the sum of the two digits: public static intd getDigit(int number)

Return sum of odd-place digits in number: public static int sumOfOddPlace(long number)

Return true if the digit d is a prefix for number: public static boolean prefixMatched(long number, int d)

Return the number of digits in d: public static int getSize(long d)

Return the first k number of digits from number. If the number of digits in number is less than k, return number: public static long getPrefix(long number, int k)

Input credit card's number from keyboard Return this credit card's number: public static long inputData()

sample outout:

Run1:

Enter a credit card number as a long integer: 4246345689049834 4246345689049834 is invalid

Run2: Enter a credit card number as a long inteter: 4388576018410707 4388576018410707 is valid

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

Students also viewed these Databases questions

Question

8. Provide recommendations for how to manage knowledge.

Answered: 1 week ago