Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Banks issue credit cards with 16 digit numbers. If you've never thought about it before you may not realize it, but there are specific rules

image text in transcribed
image text in transcribed
Banks issue credit cards with 16 digit numbers. If you've never thought about it before you may not realize it, but there are specific rules for what those numbers can be. For example, the first few digits of the number tell you what kind of card it is - all Visa cards start with 4. MasterCard numbers start with 51 through 55, American Express starts with 34 or 37 , etc. Automated systems can use this number to tell which company to contact without having to "look" at the card itself and see what the bank is on it. Another key part of the credit card number standard is the check digit. The last digit of every credit card number is determined by the previous 15 digits through a simple mathematical formula known the Luhn Algorithm. The Lhun Algorithm can be used to check if a credit card number has been corrupted in its transmission between the vendor reading the card, and the bank which has the account. It can also be used to check to see if a credit card number is valid before transmitting it to the bank. The Luhn Algorithm is described at the link above, and will be described in detail in your next project. For this lab all you need to know is that in a 16 digit credit card number, the last digit of the card is known as the check digit, and that the check digit is derived from a formula that is based on the sum of the other digits in the card, with odd and even digits being treated differently. For this lab you will write a Java program that prompts the user for a credit card number continuously until the user enters a blank line. If they enter a blank line, the loop ends and a goodbye message is displayed. If they enter a number that doesnit have exactly 16 digits, you should display an error message. Otherwise, if they enter a value that has a length of 16 , you will need to print the check digit (the last digit) and a DEBUG message that is the sum of the first 15 digits. (in your project you will see the rules for verifying an actual card number and will be asked to implement those there - for this lab just provide the sum of the digits). NOTE: You do NOT need to use arrays to solve this problem - this problem can be solved just with nested loops. Solutions that use an array where it isn't needed will be penalized in two ways. First, youre making the problem much harder than it needs to be, and second there will be a point deduction for use of an unnecessary array in the solution. Note: You will need to convert characters in your string into integer values in order to compute the sum. There are two ways to do this. The first is to use Integer, parseInt 0 and substring 0 to get a character value. The following lines of code would give you the integer value of the first character of the string input: atringg=input,aubstring(0,1);intval=Integer,paraeint(s); Another way to get a numeric value from a character is to use the method Character. getkuneric Yalue O. This takes a char value (not a String) and converts it to its correct integer value. The following lines of code would give the integer value of the first character of the String input: char a= input. charat (0); int val = Character.getNumerievalue (e); Note: You will need to conwert characters in your string into integer values in order to compute the sum. There are two ways to do this. The first is to use Integer. parseint 0 and subs tring 0 to get a character value. The following lines of code would give you the integer value of the first character of the string input: 8tringa=input.aubetring(0,1):intval=Integer.parseint(a); Another way to get a numenc value from a character is to use the method Character. gethaeric7alua 0 . This takes a char value (not a String) and converts it to its correct integer value. The following lines of code would give the integer value of the first character of the String input: char a= input-charat (0): int val = Character.getNumericvalue (c) Sample Output: This is a sample transcript of what your program should do. ltems in bold are user input and should not be put on the screen by your program. Enter a credit card nuber (enter a blank line to quit): 5457623898234112 DEBUC: Sun is 68 Check digit is: 2 Enter a credit card nuber (enter a blank line to quit) : 5457623898234113 DEBUG: Sun is 68 Check digit is: 3 Enter a credit card nuaber (enter a blank line to quit): 5555555555554 EkRORI Number MuST have exactly 16 digits. Inter a credit card nuber (enter a blank line to quit) : 5555555555544450789 EkRORI Kuaber most have exactly 16 dint tin, Enter a credit card nuaber (enter a blank line to quit); 5555555555554445 DEBUC: Sun is 72 Check digit in: 5 Enter a credit card nuaber (enter a blank line to quit): 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_step_2

Step: 3

blur-text-image_step3

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

ISBN: 0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

Handle team issues and conflict.

Answered: 1 week ago

Question

2. What should an employer do when facing an OSHA inspection?

Answered: 1 week ago