$Revision: 1.1 $
One way to increase the likelihood of correct data entry is to use checksum software to test whether the digits of a potential code number have some particular property.
For example, there is a verification scheme for the Universal Product Code (UPC) numbers. The familiar UPC in bar code form is shown below.
A valid UPC number is a 12-digit value that meets the following criteria:
r = 10 - (( m + 3 * n ) mod 10).
For this number,
m = 8 + 0 + 0 + 2 + 3 = 13 n = 7 + 0 + 7 + 1 + 1 + 5 = 21 r = 10 - ((13 + 3 * 21) mod 10) = 10 - (76 mod 10) = 10 - 6 = 4Because r = 4, the number corresponds to a possible UPC code.
Now consider the number 123456789011.
For this number,
m = 2 + 4 + 6 + 8 + 0 = 20 n = 1 + 3 + 5 + 7 + 9 + 1 = 26 r = 10 - ((20 + 3 * 26) mod 10) = 10 - (98 mod 10) = 10 - 8 = 2Because r is not equal to 1, the 12th digit, the number does not correspond to a possible UPC code.
Write a Java application that does the following (method names shown in bold print):
0. getUPCCode Prompt the user to enter a 12-digit number While the number has the wrong number of digits, Report an invalid entry and ask the user to re-enter the number 1. calculateCheckSum Extract the digits into 12 separate integers and calculate m, n, and r 2. isValid if r equals the 12th digit return true else return false 3. main getUPCCode(); calculateCheckSum(); if (isValid()) print "String [input String] is a valid UPC Bar Code." else print "String [input String] is not a valid UPC Bar Code."Assume the user will enter only digits 0 through 9 and read the input into a String in step 0. You will need to convert each of the characters in this String to an int to do arithmetic on them in step 1. There are at least two ways to do this conversion:
Since this is a Java Application, you should also write a main method. The main method should be used to call other methods as shown above in step 3. You should declare all the methods and the non-local variables to be static.
When your program compiles and run correctly, submit the Java source file using the CS 101 Submission Website. Make sure you submit the Java source file: the filename should end in ".java", not ".java~" or ".class".