Determine whether a given credit card number is valid or not

Assignment Help JAVA Programming
Reference no: EM131082000

Credit Card (Luhn's algorithm) - Java program - using API

Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits. It must start with 4 for Visa cards, 5 for Master cards, 37 for American Express cards, and 6 for Discover cards. In 1954, Hans Luhn of IBM proposed the following algorithm for validating credit card numbers:

a. Double every second digit from right to left (e.g., if number is 3 => 3 * 2 => 6) and add them together.

b. If this doubling results in a two-digit number, then add the two digits to get a single-digit number (e.g., if number is 5 => 5 * 2 => 10 => 1+0 => 1).

So, for the credit card number 4388576018402626, doubling all second digits from the right results in (2 * 2 = 4) + (2 * 2 = 4) + (4 * 2 = 8) + (1 * 2 = 2) + (6 * 2 = 12 = 1 + 2 = 3) + (5 * 2 = 10 = 1 + 0 = 1) + (8 * 2 = 16 = 1 + 6 = 7) + (4 * 2 = 8).

This totals to 4 + 4 + 8 + 2 + 3 + 1 + 7 + 8 = 37. Add all digits in the odd places from right to left.

The leftmost digit of the credit card number is at index 0; 6 + 6 + 0 + 8 + 0 + 7 + 8 + 3 = 38.

Add results from steps (a) and (b) and see if divisible by 10. If it is, then the card number is valid; otherwise invalid. 37 + 38 = 75 is not divisible by 10, so it is an invalid credit card number.

Implement Luhn's algorithm in a program to determine whether a given credit card number is valid or not. You must test if the number of digits in the input is in the valid range (13 to 16), run Luhn's algorithm to test its validity, and if it is valid, print the name of the company that offers that credit card number.

CreditCard

El Attributes

+ private int evenSum + private int oddSum
+ private int sum
+ private String ccNumber + private String company 2 Operation.
+ public boolean isDivisibleBy10()
+ public boolean isValid()
+ public boolean validateCompany()
+ public boolean validateLength()
+ public boolean validateNumber()
+ public boolean validateSums()
+ public C-editCard(String num) + public int getEvenSum()
+ public int getOddSum() + public int getSum()
+ public Sting getCcNumber() + public Sting getCompany().

Reference no: EM131082000

Questions Cloud

Determine the exact interval of convergence : Sample final questions. For each power series, determine its radius of convergence R. By considering the series at x = ±R, determine the exact interval of convergence
What do you think is a good size for a team : What do you think is a good size for a team? What do you think is best in school and also in the workplace - a large team or a small one? If there are many members on a team, does that make some feel that they can slack off more,
Example of a country other than the us : Give an example of a country other than the US outsourcing to another country other than the US?
Are h3 and h2 independent events : Are H3 and H2 independent events?
Determine whether a given credit card number is valid or not : Implement Luhn's algorithm in a program to determine whether a given credit card number is valid or not. You must test if the number of digits in the input is in the valid range (13 to 16), run Luhn's algorithm to test its validity.
How many possible starting lineups are there : how many possible starting lineups are there?
Good-faith drug testing programs : Most good-faith drug testing programs are legally acceptable if the organization has taken four steps. What are they?
How many outcomes are in the sample space : How many outcomes are in the sample space?
Negligent for the killing of the silver back gorilla : Do you think the parents should be held negligent for the killing of the silver back gorilla in Ohio? Why or Why not? Give three supporting facts to support your opinion. Write a two page paper. Also, remember to cite your sources.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Initializing static fields

Why do static ?elds of a class have to be initialized when the class is loaded? Why can't we initialize static ?elds when the program starts? Give an example of what goes wrong if, instead of static ?elds being initialized too early, they are init..

  What significant justification is there for the -> operator

Dynamic type binding is closely related to implicit heap-dynamic variables. Explain this relationship. Keep your answer to 1 paragraph or less.

  How can worms and viruses be introduced to a web site

Include ways that a Website can be attacked by malicious users such as Java script insertion, SQL insertion, hidden field manipulation, header manipulation and cookies

  Creat a class named vehicle that acts as a superclass

Write a UseVehicle class to instantiaate the two Vehicle objects and print the objects values. Save as UseVehicle.java

  What are the values of these boolean expressions

Describe the steps for inserting a new item at the head of a linked list? Make sure you consider all possible incoming conditions.

  The fileiohelper class provides 2 class methods

1.int FileIOHelper.getNumberofStudents(String fileName): takes a String parameter which is the name of an input file in the format described above, and returns the number of students in the file

  Vehicle in vehicle.java

Create a class called Vehicle in Vehicle.java with instance variables make (such as Ford, GM, Chrysler, Toyota, or Honda), year, and horsepower (200, 300, and 400). Add the necessary constructor and set and get methods.

  Create a program that simulates a slot machine

Create a program that simulates a slot machine. To decide which loop structures to use, such as while, do while, and for loop in Java. To use decision structures such as if, if-else, and switch statements in Java

  Create a program in java that displays hello world

Create a program in Java that displays "Hello world!", No Design Section is required for this assignment, Copy and Paste your code into the Source Programs section and a screen shot of the results in the Output section.

  Calculates the cost of a mortgage

Write a class called Mortgage that calculates the cost of a mortgage. Prompt the user to enter the principal amount, the term in years, and the interest rate per year.

  Is it possible to increase/decrease the diameter of circle

GeneralPath star = new GeneralPath(GeneralPath.WIND_EVEN_ODD, xPoints.length); // create GeneralPath object

  Writing a program to have it generate random words

How would I go about writing a program to have it generate random words with a letter missing for a child to guess? Maybe it would have three letters, then four, next five, and so on until maybe 10 letters. Please keep in mind that I'd like it to wor..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd