Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming [20 marks] Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits. It must start with

Java Programming

image text in transcribedimage text in transcribed

[20 marks] 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*26) and add them together. 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 552>101+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)(12 2)(6 2 12 12 3)52 10- 1+0 (8 2 16 167)(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. b. 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 a Attributes + private int evenSum + private int oddSum + private int sum + private String cCNumber + private String company a Operations +public boolean isDivisibleBy100 + public boolean isValidO +public booean validateCompany) + public boolean validateLengthO +public booean validateNumber +public boolean validateSumsO + public CreditCard(String num) + public int getEvenSum + public int getoddSumO + public int getsum(O + public String getCcNumberO) +public String getCompany0

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

Creating A Database In Filemaker Pro Visual QuickProject Guide

Authors: Steven A. Schwartz

1st Edition

0321321219, 978-0321321213

More Books

Students also viewed these Databases questions

Question

Apply your own composing style to personalize your messages.

Answered: 1 week ago

Question

Format memos and e-mail properly.

Answered: 1 week ago