Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please write in java. Thank you! PROBLEM 1 For faster sorting of letters, the United States Postal Service encourages companies that send large volumes of
Please write in java. Thank you!
PROBLEM 1 For faster sorting of letters, the United States Postal Service encourages companies that send large volumes of mail to use a bar code denoting the ZIP code see Figure 1: Example Zip Encoding. Until 2013, the encoding scheme for a five-digit ZIP code was known as POSTNET. The encoding of each numerical digit is shown in Table 1: Zip Code Digit Encoding Values. In addition to the Value Encoding bars for each digit, there are full-height frame bars on each side of the bar code see ull Figure 2: Encoded Digit Grouping. 2 The five encoded digits are followed by a check digit, which is computed as follows: ulil Take the sum of the digits and choose the check digit to make the sum a multiple of 10. For an example checksum calculation, see Equation 1: Example Checksum Calculation. Each digit of the ZIP code, and the check digit, is encoded according to the table at right. For this problem, we will write a program that allows the user to instantiate a zip code object using the bar code or numeric value and allow the user to convert the value to either a numerical or bar code format. To represent the encoding bars, we will use . for half bars and for full bars. For example, 95014 represented as a bar code would be ....1.1. || ......||.|..|... || Equation 1: Example Checksum Calculation Checksum Calculation: Lu Consider the ZIP code 95014. The sum of each digit is 9 + 5 + 0 + 1 + 4 is 19 Table 1: Zip Code Digit Encodina Values The check digit would be 1 to make the sum equal to a multiple of 10 (i.e., 19 + 1 = 20). JFebruary 18-1/13 llu *************** ECRLOT ** C057 - Frame bars CODE C671 RTS2 JOHN DOE 1009 FRANKLIN BLVD SUNNYVALE CA 95014 - 5143 C057 ielu lilo ll... ull olul li Digit 1 Digit 2 Digit 3 Digit 4 Digit 5 Check Digit Figure 2: Encoded Digit Grouping IIIIIIIIIIIIIIIIIIIIII Figure 1: Example Zip Encoding 1. Create a Java file called clszipcode.java. Do not add a main() method to clszipcode.java. 2. At the top of your .java file add the following documentation comments // Your Name // CS110 Section XX // Assignment XX // Todays Date 3. Create a constant instance variable of type String[] named DIGITCODES and assign the elements from Table 1: Zip Code Digit Encoding Values using the digit value as the position in the string array. HINT: ARRAYS ARE ZERO INDEXED, START WITH THE ENCODED REPRESENTATION OF O FOR POSITION O IN THE ARRAY. 4. Create an instance variables of type String named strzipBarCode. 5. Create an instance variable of type int named intzip. 6. Create an overloaded constructor of clsZipCode with one parameter of type int named zip. This constructor will store the zip code in the instance variable intzip and will convert the zip to its bar code representation and store it in strzipBarCode. a. In the body of the constructor, do the following: i. Assign the value of the parameter zip to the instance variable intzip. ii. Assign the empty string to the instance variable strzipBarCode. iii. Create two local variables of type int named intdigit and intchecksum and assign O to intdigit and intchecksum. 2/13 iv. Use a loop to iterate over each single digit number in intzip and convert it to its string representation of the encoded value using the index of DIGITCODES for the digit encoding. HINT: USE A LOOP TO DIVIDE INTZIP BY POWERS OF TEN FROM 10 TO 104. FOR EACH ITERATION OBTAIN THE REMAINDER OF THE CURRENT QUOTIENT DIVIDED BY TEN AND ADD THE VALUE TO INTCHECKSUM. 1. In the body of the loop, concatenate the string representation of the encoded value to strzipBarCode. v. Calculate the value of the check digit by summing each single digit number value in the zip code and calculating the difference between the value and the closest multiple of 10. vi. Convert the check digit to an encoded value and append the value to the end of strzipBarCode. b. Add a JavaDoc comment before the constructor signature with an explanation of your choice. The JavaDoc must be a complete sentence and explain what the method does. The parameter must be explained. 7. Create an overloaded constructor of clsZipCode with one parameter of type String named zipBarCode. This constructor will store the bar code representation of a zip code in strzipBarCode and will convert the bar code to its numerical representation and store the numerical value in the variable intzip. a. In the body of the constructor, do the following: i. Assign the value of the parameter zipBarCode to the instance variable strzipBarCode. ii. Create two local instance variables of type String named strdigits and strcurrentDigitBarCode and assign the empty string to strdigits and strcurrentDigitBarCode. iii. Use a loop to iterate 5 times. We will use each iteration to calculate a substring and convert the encoding to a numerical digit. 1. In the body of the loop, do the following: a. Create a substring of strzipBarCode for the 5 bars representing the current digit using the substring() method. HINT: SUBSTRING(
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started