Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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. **************** ECRLOT ** C057 CODE C671RTS2 JOHN DOE 1002 MONTANA BLVD SUNNYVALE CA 95014-5143 ||ll||llllllllllll||ll|| Digits 1 3 4 5 6 7 8 9 Check Digit Frame Bars The encoding scheme for a five-digit ZIP code is shown above. There are full height frame bars on each side. The five encoded digits are followed by a correction digit, which is computed as follows: Add up all the digits, and choose the correction digit to make the sum a multiple of 10. For example, the ZIP code 95014 has sum of digits 19, so the correction digit is 1 to make the sum equal to 20. Each digit of the ZIP code, and the correction digit, is encoded according to the following table: 7 0 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 4 0 0 0 1 1 1 0 0 0 1 2 0 1 1 0 0 1 0 0 1 0 1 1 0 1 0 1 0 0 1 0 0 1 1 0 1 0 0 1 0 0 0 1 1 1 where 0 denotes a half bar and 1 a full bar. Note that they represent all combinations of two full and three half bars. The digit can be easily computed from the bar code using the column weights 7,4, 2, 1, 0. For example, 01100 is 0*7 + 1*4 + 1*2 + 0*1 + 0*0 = 6. The only exception is 0, which would yield 11 according to the weight formula. For this assignment, you are to create a Java Application, named PostalBarCode, which performs the following conversion processing. Your program should include a toZipCode method that accepts a bar code string and returns the converted zip code string and a toPostalBarCode method that accepts a zip code string and returns the converted bar code string. Your application should contain two text fields with appropriate labels: A Zip Code text field for entry and display of a Zip Code string A Postal Bar Code text field for the entry and display of a Postal Bar Code string. Your application should contain the following three buttons with associated event handling: A button, with label Bar, for converting a zip code to bar code. When the associated event is handled, the program should read the entered zip code string from the Zip Code text field, invoke the toPostalBarCode method, and then display the converted postal bar code in the Postal Bar Code Text Field. Your program should be able to handle both the 5-digit (i.e. 18512) and 9-digit (i.e. 18512-1602) zip codes. An error should be displayed when the input zip code does match one of these formats. A button, with label Zip, for converting a bar code to a zip code. When the associated event is handled, the program should read the entered bar code string from the Postal Bar Code text field, invoke the toZipCode method, and then display the converted Zip Code in the Zip Code text field. An error should be printed when the input bar code is not valid. A button, with label Clear, for clearing text fields. When the associated event is handled for this button, both the zip code and bar code text fields should be cleared. Use :' for half bars, l' for full bars. For example 95014 becomes 1:1:::1:1:||::::::||: ::1:::111 The variables and methods defined within your Java classes must include comments. Your program should also be properly formatted, which includes indentation of code
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