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

  Alter the prototype form page by javascript function

Alter the prototype form page so that when JavaScript function has verified that all the required fields have been filled, cookie is added to user's computer.

  Write a short java method to count the number of nodes

Write a short Java method to count the number of nodes in a circularly link list.

  Identifing the appropriate class names, attributes & methods

I am having problems identifing the appropriate class names, attributes and methods for the following objects. I need at least 3 attributes and 3 methods for each class.

  Write a java program the displays the state bird

Write a Java program the displays the State bird and flower. The program should prompt the user to enter a State and print both the State bird and flower.

  Prepare a program that constructs a binary tree

Write your own implementation of primitive operations and use self-referential classes in your implementation.

  Give two different ijvm translations for the given java code

Give two different IJVM translations for the following Java statement: i = k + n + 5; Give the Java statement that produced the following IJVM code:

  Design a function named "falling distance"

Design a function named "fallingDistance" that accepts an objects falling time, in seconds, as an argument. The function should return the distance, in meters, that the object has fallen during that time interval. Design a program that calls the func..

  Develop a reliable transfer protocol over udp

Develop a reliable transfer protocol over UDP. Focus on a Stop- and-Wait protocol.

  Java program that reads an input

Create a java program that reads an input of n lines with the first line being the number of people in the contest and the remaining lines a numeric 9 digit code for each person that gets a vote

  Design and implement a small and simple email server

Design and implement a small and simple email server using the concept of web based information system (WBIS).

  Develop a complex web site

Develop a complex web site or piece of multimedia from scratch, using information gathering and design techniques;

  Write specifications for method which advances date by one

Write specifications for the method which advances any given date by one day. Comprise a statement of purpose, pre- and post-conditions, and description of parameters.

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