Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class that represents a credit card. Call this class CreditCard . The class will have the following fields and methods: A constructor which

Write a class that represents a credit card. Call this class CreditCard. The class will have the following fields and methods:

A constructor which takes a String to set the card number. Ignore dashes, spaces, and any other non-digit characters.

A public method called toString that returns the credit card number.

Add the following data and operations to CreditCard:

  • A public method called getIssuer that returns the String name of the company who issued the credit card. Popular issuers are as follows:
Issuer Identifier Card Number Length
Diner's Club/Carte Blanche 300xxx-305xxx, 36xxxx, 38xxxx 14
American Express 34xxxx, 37xxxx 15
VISA 4xxxxx 13, 16
MasterCard 51xxxx-55xxxx 16
Discover 6011xx 16
  • Modify toString to include the issuer's name.

Add the following data and operations to CreditCard:

  • A public method called isValid which returns a boolean value representing the validity of the card number.

    The algorithm can be described as follows: "For a card with an even number of digits, double every odd-numbered digit and subtract 9 if the product is greater than 9. Add up all the even digits as well as the doubled-odd digits, and the result must be a multiple of 10 or it's not a valid card. If the card has an odd number of digits, perform the same addition doubling the even numbered digits instead."

    For example, "[Let's] apply the Luhn check to 4408 0012 3456 7890. (4*2)+4+(0*2)+8+(0*2)+0+(1*2)+2+(3*2)+4+(5*2-9)+6+(7*2-9)+8+(9*2-9)+0 = 8+4+0+8+0+0+2+2+6+4+1+6+5+8+9+0 = 63, which is not a multiple of 10. Therefore we conclude that the number 4408 0012 3456 7890 is an invalid credit card number."

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

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions

Question

5. What is the role of social justice in community psychology?

Answered: 1 week ago