$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:

- Let m be the sum of the 2nd, 4th, 6th,
8th, and 10th digits (where the numbering of digits is from left to
right.)
- Let n be the sum of the 1st, 3rd, 5th, 7th, 9th,
and 11th digits.
- Let
r = 10 - (( m + 3 * n ) mod 10).

- A number meets the UPC encoding criteria if its 12th digit equals r.

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.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:getUPCCodePrompt 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.calculateCheckSumExtract the digits into 12 separate integers and calculate m, n, and r 2.isValidif r equals the 12th digit return true else return false 3.maingetUPCCode(); 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."

- Get each char out of the String and then use the static method in the Character class called "getNumericValue" to convert the char to an int.
- Get each single letter substring from the String and then use the static method in the Integer class called "parseInt" to return the int value of the String.

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".**