Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm having trouble with this assignment, I know this has been posted before but in all of the responses I have not seen anyone use

I'm having trouble with this assignment, I know this has been posted before but in all of the responses I have not seen anyone use replaceAll() to remove slashes and/or dashes from entered Strings. Not sure how to get this one started, hopefully I can get some help! thanks in advance :)

Write a program that checks to see if a credit card number is valid.

Constraints

The credit card number (CC#) must be 16 digits in length

The CC# can be in either form: ####-####-####-#### or ################

The Expiration Date (Exp) must be in the form: MM/YY (Example: 12/15)

Notify user of correct entry form for CC# and Exp

Name, CC#, and Exp must be entered as Strings

Use a separate (external to the main class) subclass, VerifyCard() to validate the CC# with the following private method conditions:

o Condition 1: The first digit must be a 4 o Condition 2: The fourth digit must be one greater than the fifth digit o Condition 3: The product of the first, fifth, and ninth digits must be 24 o Condition 4: The sum of all digits must be evenly divisible by 4 o Condition 5: The sum of the four digits in the expiration date must be less than the product of the last two digits of the card number o Condition 6: The sum of the first four digits must be one less than the sum of the last four digits o Condition 7: If you treat the first two digits as a two-digit number, and the 15th and 16th digits as a two digit number, their sum must be 100 (Example: 4643262531465454 -> 46 + 54 = 100)

Requirements

Ask the user for the name on the credit card

Ask the user for the credit card number

Ask the user for the expiration date

Use set and get methods in the subclass for the information entered by the user (Don't forget to create and use a separate (external to the main class) subclass, VerifyCard() to validate the CC# with the following private method conditions:)

Set methods must be private

All Condition listed in Constraints should be private methods

Use a regex String for Condition 1

Most Condition methods will use an if statement

Condition methods 4-6 will need one to two for loops to step through the int arrays

This program will utilize code learned from Week 1 through Week 10

Hints

CC# and Exp can be converted into int Arrays

The following CC#s can be used as test cases. Each of these numbers will return as valid. Make sure you change them around or enter other CC#s that are not valid:

o 4192112566331259

o 4283253533222358

o 4374398522116157

o 4292154566732358

o 4553223534333555

o 4643262531465454

o 4732169566119053

o 4823287533234752

Each of the CC#s will work with an Exp of 12/15. By increasing the YY, you may find that a few of these cards will not be valid

Consider using the .replaceAll() method to remove slashes and/or dashes from entered Strings

Consider using the .split() method when converting the Strings to int Arrays

The .parseInt() method and the Integer class can be your friend in this assignment

Expected Output

The sample output below has executed three runs of the program. User input is in BOLD.

Enter Card Holder's Name: Tom Jones Enter Credit Card Number (No dashes): 4553223534333555 Enter Credit Card Expiration Date (MM/YY): 12/15

Card number: 4553223534333555 is a valid credit card.

Run program again? (Y for Yes, N for No): y Enter Card Holder's Name: Dean Martin Enter Credit Card Number (No dashes): 4732169566119053 Enter Credit Card Expiration Date (MM/YY): 12/15

Card number: 4732169566119053 is a valid credit card.

Run program again? (Y for Yes, N for No): Y Enter Card Holder's Name: Frank Sinatra Enter Credit Card Number (No dashes): 4234253533211358 Enter Credit Card Expiration Date (MM/YY): 12/15

Card number: 4234253533211358 is NOT a valid credit card.

Run program again? (Y for Yes, N for No): n Thank you. Goodbye!

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_2

Step: 3

blur-text-image_3

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 Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions

Question

a. What is the name of the university?

Answered: 1 week ago