Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program called Assignment4 (saved in a file Assignment4.java) that reads a credit card number and checks to see if it is valid or

Write a program called Assignment4 (saved in a file Assignment4.java) that reads a credit card number and checks to see if it is valid or invalid.

The last digit of a credit card number is the check digit, which protects against transcription errors such as an error in a single digit or switching two digits. The following method is used to verify actual credit card numbers but, for simplicity, the description is for numbers with 8 digits instead of 16 digits:

Starting from the rightmost digit, form the sum of every other digit. For example, if the credit card number is 43589795, then you form the sum 5 + 7 + 8 + 3 = 23.

Double each of the digits that were not included in the preceding step. Add all digits of the resulting numbers. For example, with the numbers given above, doubling the digits, staring with the next to last one, yields 18 18 10 8. Adding all digits in these values yields 1 + 8 + 1 + 8 + 1 + 0 + 8 = 27.

Add the sums of the two preceding steps. If the last digit of the result is 0, the number is valid. In our case 23 + 27 = 50, so the number is valid.

Write the program that implements this algorithm. The user will enter an 8-digit number, and the program prints out whether the number is valid or not. If it is not valid, the program should print thevalue of the check digit that would make it valid. The program will keep checking for valid credit card numbers until user enters no to exit the program.

Without utilizing arrays.

Sample run:

Enter the credit number: 43589795

Valid!

Check another credit card(y/n)? Y

Enter the credit number: 43589790

Invalid, the check digit should be 5

Check another credit card(y/n)? Y

Enter the credit number:

40589095 Valid!

Check another credit card(y/n)? Y

Enter the credit number: 12345678

Invalid, the check digit should be 4

Check another credit card(y/n)? N

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

Advances In Spatial And Temporal Databases 8th International Symposium Sstd 2003 Santorini Island Greece July 2003 Proceedings Lncs 2750

Authors: Thanasis Hadzilacos ,Yannis Manolopoulos ,John F. Roddick ,Yannis Theodoridis

2003rd Edition

3540405356, 978-3540405351

More Books

Students also viewed these Databases questions

Question

=+ Is the needed level available from outside sources?

Answered: 1 week ago

Question

outline some of the current issues facing HR managers

Answered: 1 week ago