Goal: Print Address with POSTNET bar code. (POSTNET means Postal Numeric Encoding Technique.) Here is an example of such an address: See image.

We will use the vertical line ( | ) to represent the long vertical bar and semicolon ( : ) to represent the short vertical bar

Input File attached: addresses.txt (Naming this input file with a .csv extension is also okay, but then it opens up in Excel if you double click on its name in the Windows Explorer.)

Details:

1.Read an input CSV file containing addresses using a Scanner object. Don't redirect from stdin, read directly from the file. Here are two sample lines from a mailing list:

Anna Lee,123 Nice Street,Memphis,TN,38141-8346

Stan Smith,456 De La Vina Street,Santa Barbara,CA,93101-3298

2.Obtain the input file using a JFileChooser dialog. See the UseFileChooser Example in the input-output examples file.

3.For each line write out an address like this to stdout:

Anna Lee
123 Nice Street
Memphis TN 38141-8346
|::||:|::|::::||:|::|:::|||::|:::||::|::|:||::::|:||

Stan Smith
456 De La Vina Street
Santa Barbara CA 93101-3298
||:|::::||::::||||::::::||::||:::|:||:|::|::|:::|:||

4.The bar code is encoded using this table:

1 2 3 4 5 6 7 8 9 0
:::|| ::|:| ::||: :|::| :|:|: :||:: |:::| |::|: |:|:: ||:::

In addition to encoding the 9 digits of the zip code, the bar code includes initial (i) and terminal (t) frame bars and a check sum (cs), which is 10 - the sum of the zip code digits mod 10. Thus the zip code 38141-8346 is encoded like this:

i 3 8 1 4 1 8 3 4 6 cs t
| ::||: |::|: :::|| :|::| :::|| |::|: ::||: :|::| :||:: ::|:| |

The sum of the digits is 38 and 38 % 10 is 8, so the check sum is 10 - 8 = 2. The initial and terminal frame bars are always |.

Note: If the sum of the digit % 10 is 0, the check sum is 10 - 0 = 10, which should be replaced by 0. This can be done with an if statement, or with

checksum %= 10

See this article for more details: http://en.wikipedia.org/wiki/POSTNET

5.Write and use this method:

public static String getBarCode(String zipcode)
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.