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

  Explain the tasks occur in exception handling

Calculate the letter grade the student has earned based on the average of these assignments.

  Executing stringed musical instrument class

Create and execute a stringed musical instrument class.

  System schedule on a multiprocessor-multicore environment

This program assignment is provided to let the students understand how to the Operating Systems schedule all the processes on a multiprocessor or multicore environment.

  Write a java program to simulate a die

Write a Java program to simulate a die. A die has values of either 1, 2, 3, 4, 5 or 6 on the face. You should use the Math.Random() or the java.util.Random() class to generate the values on the die.

  Create a servlet to display a table

NetBeans for Java with GlassFish/Tomcat: https://netbeans.org/downloads/ (select All option)) and create a servlet to display a table that contains factorials for the numbers from 0 to 10, as shown

  Class pointparameters

What is the output of the following Java program? Explain in terms of how parameters are passed in Java.import java.awt.*;class PointParameters

  How are the packaged files viewed

How are several Java files packaged, Why is there a need for packaging java files and How are the packaged files viewed?

  Each purchase contains an invoice number amount of sale

Create a class named Purchase. Each Purchase contains an invoice number, amount of sale, and amount of sales tax. Include set methods for the invoice number and sale amount.

  Punished for minor infractions given their mental illness

What if you a Disciplinary Hearing Officer in a unit with mentally ill inmates? How would you sanction offenders for infractions without punishing them for their illnesses? Do you think they should be punished for minor infractions given their mental..

  Write a bag class with a generic type

Write a Bag class with a generic type. Write a class such as item that has a name and price. Add objects of item to the bag and find the average and the total of the price of all items in the bag.

  Create wheel 360 degree

You have to create wheel, 360 degree. That is numbered 0-36. it is supposed to be spun, and randomly lands on one of the numbers.

  Writing messages to a serversocket in java

the server must accept a connection before the client can communicate.

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