Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java, Thanks 11.11 Credit Card Check Digit Intro - Lab Banks issue credit cards with 16 digit numbers. If you've never thought about it

image text in transcribedimage text in transcribedimage text in transcribedIn Java, Thanks

11.11 Credit Card Check Digit Intro - Lab 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 doesn't 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, you're 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() and substring() to get a character value. The following lines of code would give you the integer value of the first character of the string input: String s = input.substring(0,1); int val = Integer.parseInt(s); Another way to get a numeric value from a character is to use the method Character.getNumericValue(). 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 c = input.charAt(0); int val = Character.getNumericValue (c); Sample Output: This is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen by your program. Sample Output: This is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen by your program. Enter a credit card number (enter a blank line to quit): 5457623898234112 DEBUG: Sum is 68 Check digit is: 2 Enter a credit card number (enter a blank line to quit): 5457623898234113 DEBUG: Sum is 68 Check digit is: 3 Enter a credit card number (enter a blank line to quit): 5555555555554 ERROR! Number MUST have exactly 16 digits. Enter a credit card number (enter a blank line to quit): 55555555555544456789 ERROR! Number MUST have exactly 16 digits. Enter a credit card number (enter a blank line to quit): 5555555555554445 DEBUG: Sum is 72 Check digit is: 5 credit card number (enter a blank line to quit): Goodbye! 285900. 1760016 Downloadable files LuhnAlgorithm.java Download LuhnAlgorithm.java Load default template... 1 /** 2 * DESCRIPTION OF PROGRAM HERE 3 4 * @author YOUR NAME HERE * @version DATE HERE */ b 7 7 import java.util.Scanner; 8 8 9 public class LuhnAlgorithm { 19 11 public static void main(String[] args) { 12 // TO DO: Enter your code here between the curly braces 13 } 14 } Develop mode Submit mode When done developing your program, press the Submit for grading button below. This will submit your program for auto-grading

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

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions

Question

Q .1. Different ways of testing the present adulterants ?

Answered: 1 week ago

Question

Q.1. Health issues caused by adulteration data ?

Answered: 1 week ago

Question

1. Traditional and modern methods of preserving food Articles ?

Answered: 1 week ago

Question

What is sociology and its nature ?

Answered: 1 week ago

Question

1. Who should participate and how will participants be recruited?

Answered: 1 week ago