Question: Print Address with POSTNET bar code in Java. Please write this in Java, please write comments as you create it, and please follow the coding
Print Address with POSTNET bar code in Java.
Please write this in Java, please write comments as you create it, and please follow the coding instructions.
Goal: Print Address with POSTNET bar code. (POSTNET means Postal Numeric Encoding Technique.) Here is an example of such an address: We will use the vertical line ( | ) to represent the long vertical bar and semicolon ( : ) to represent the short vertical bar
Input File: 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.)
addresses.text looks like this:
Anna Lee,123 Nice Street,Memphis,TN,38141-8346 Stan Smith,456 De La Vina Street,Santa Barbara,CA,93101-3298 Meredith Baker,1343 Maple Avenue,Denver,CO,80236-2982 Julia Chen,336 Euclid Avenue,Cleveland,OH,44120-4321 Jason Sanchez,4320 West Diversey Avenue,Chicago,IL,60738-7609
Details:
- 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
- Obtain the input file using a JFileChooser dialog. See the UseFileChooser Example in the input-output examples file.
UseFileChooser Example looks like this:
import java.io.*; import java.util.Scanner; import javax.swing.JFileChooser; public class UseFileChooser { public static void main(String[] args) throws FileNotFoundException { // Open file containing names with FileChooser dialog JFileChooser chooser = new JFileChooser( ); chooser.showOpenDialog(null); File fileObj = chooser.getSelectedFile( ); // Read names and write greetings, each in their own file. Scanner in = new Scanner(fileObj); while (in.hasNextLine( )) { String name = in.nextLine( ); String greeting = "Hello " + name + ", how are you?"; PrintWriter pw = new PrintWriter(name + ".txt"); pw.println(greeting); pw.close( ); } in.close( ); } } - For each line write out an address like this to the output file labels.txt:
Anna Lee 123 Nice Street Memphis TN 38141-8346 |::||:|::|::::||:|::|:::|||::|:::||::|::|:||::::|:|| Stan Smith 456 De La Vina Street Santa Barbara CA 93101-3298 ||:|::::||::::||||::::::||::||:::|:||:|::|::|::|::||
- The bar code is encoded using this table:
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:1 2 3 4 5 6 7 8 9 0 :::|| ::|:| ::||: :|::| :|:|: :||:: |:::| |::|: |:|:: ||::: 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 withchecksum %= 10
Putting this together, you can compute the checksum like this:checksum = (10 - sumOfDigits % 10) % 10
See this article for more details:- http://en.wikipedia.org/wiki/POSTNET
- Write and use this method:
public static String getBarCode(String zipcode)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
