A3-Postal Bar Codes

On This Page


Background Information for Project

To sort letters more quickly, the United States Postal Service encourages companies to add a bar code to large volume mailings. One such bar code format is POSTNET "A" which encodes the five digit zip code of the address. The following is an example of a POSTNET A five-digit bar code (from Wikipedia).

Example POSTNET 5-digit barcode

POSTNET A bar codes are made up of long and short bars as shown in the diagram below. The diagram also shows the psuedo-binary encoding scheme you can use to decode bars. For example, the number 10100 is 1 x 7 + 0 x 4 + 1 x 2 + 0 x 1 + 0 x 0 = 9. The only exception to the coding scheme is 0, which is encoded as 11 according to the formula.

POSTNET barcode encoding

The layout of a five-digit zip code is shown below. Each side has a full-height frame bar. Inside the frame bars are the five encoded digits followed by a check digit. The check digit is computed by adding up all five digits of the zip code. The check digit is the smallest number you need to add to the sum to make the entire code a multiple of 10. For example, the code 91801 adds up to 19, so the check digit is 1 to make the sum equal to 20.

POSTNET 5-digit layout

More Information

Example Operation

Enter a 5-digit zip code (0 to exit): 95003
The bar code for ||,|,,,|,|,||,,,||,,,,,||,,,||,|
Enter a 5-digit zip code (0 to exit): 90210
The bar code for ||,|,,||,,,,,|,|,,,||||,,,|,,|,|
Enter a 5-digit zip code (0 to exit): 00509
The bar code for |||,,,||,,,,|,|,||,,,|,|,,,||,,|
Enter a 5-digit zip code (0 to exit): 0

May your mail zip to its destination!

Also, you can download and run the asn03demo.jar file to see how it operates. Note that you cannot double-click the JAR file and must run the demo from the command line:

java -jar asn03demo.jar

Also note that the JAR file may contain some extra credit features.

Program Specifications

  1. Write a class named PostalApp that asks the user for a zip code and prints the POSTNET A bar code to the console.

    Be sure to include the frame bars and check digit in the bar code displayed.

  2. The PostalApp class must contain the following public method:
    /**
        Creates a POSTNET "A" bar code for a ZIP code.
    
        @param zip the code to convert to a barcode.
        @return a bar code of the zip using "|" as the long
        bar and "," as the half bar.
    */
    String makeBarcode(String zip) { }
    

    You may add other methods as needed.

  3. When creating barcodes, use a vertical bar '|' for full bars and a comma ',' for half bars. For example, 95003 (Cabrillo's zip code) becomes:
    ||,|,,,|,|,||,,,||,,,,,||,,,||,|
  4. Your program must follow the same sequence of operations as the Example Operation including:
    1. No extra inputs other than entering a zip code
    2. Using 0 as a sentinel to exit the program
  5. Your PostalApp class must pass all the tests of the Test Cases provided below.
  6. Do not use any package statements.
  7. Submit your files to Blackboard as explained in the section of this document: What to Turn In.

Hints

  1. You will need to extract each digit singly to add up the checksum.

Test Cases

Testing is an important part of software development. Usually, programmers develop tests for each unit of code they produce. This is know as "unit testing" and allows the programmer to verify that the code they develop works correctly.

To assist you in developing your code, I provide tests for this assignment. These tests, known collectively as "test cases", help to make sure that your assignment meets its requirements. I will use these test cases (and perhaps others) to test your assignment, and you should too. If the test cases do not pass, then you will lose points for the assignment.

Install the tests by copying the following file into the same directory as your .java source code files:

Compile and run the test class as you would any other Java program. You may need to compile your source code before compiling and running the test code.

Extra Credit

The following are worth extra credit points:

  1. Add a method to your PostalApp class using the following heading that returns the barcode as a string:
    /**
        Read a valid zip code from the keyboard.
    
        @param input The Scanner object.
        @return a valid zip code.
     */
    public String readValidZip(Scanner input) { }
    
    Be sure to use this exact heading or you will not get credit. Grading:
    • 1 point for validating the length is exactly 5 characters, except when a "0" is entered
    • 1 point for validating all characters are number symbols

    Example Operation:

    Enter a 5-digit zip code (0 to exit): 509
    ZIP codes must be 5 digits.
    Enter a 5-digit zip code (0 to exit): abc12
    Enter numbers only.
    

Make certain that your README.txt file describes any extra credit attempted.

Grading Criteria

The instructor will evaluate your assignment using the following criteria. Each criteria represents a specific achievement of your assignment and has a scoring guide. The scoring guide explains the possible scores you can receive.

Some scoring guides have a list of indicators. These indicators are a sign of meeting, or a symptom of not meeting, the specific criterion. Note that a single indicator may not always be reliable or appropriate in a given context. However, as a group, they show the condition of meeting the criterion.

For information on grading policies, including interpretation of scores, see the course information page.

Program Compilation

  • 4: Source code compiles with no errors or warnings
  • 2: Source code compiles with warnings
  • 0: Does not compile

Functionality

  • 10: Demonstrates mastery of the assignment
    • Has extra features or demonstrates techniques beyond the assignment
    • Applies concepts from the lesson(s) appropriately
    • Meets all specifications (see above) with particularly elegant solutions
    • No errors encountered during operation
    • All test cases pass
  • 8: Has all the functionality expected of the assignment
    • Demonstrates many techniques from the lesson
    • Meets all specifications (see above)
    • Implementation seems more complicated than necessary.
    • May have one minor error
    • All test cases pass
  • 6: Has most of the functionality expected of the assignment
    • Demonstrates some techniques from the lesson
    • Meets all but one of the specifications (see above)
    • Implementation seems excessively complicated.
    • May have 2-3 minor errors
    • All but one test case passes
  • 4: Has some of the functionality expected of the assignment
    • Demonstrates some techniques from the lesson
    • Meets at least 1/2 of the specifications (see above)
    • Implementation seems excessively complicated.
    • May have more than 3 minor errors
    • At least 1/2 of all test cases pass
  • 2: Serious functional problems but shows some effort and understanding
    • Meets less than 1/2 of the of the specifications (see above)
    • Has a major error or many minor errors
    • Implementation seems very convoluted
    • Demonstrates few techniques from the lesson
    • Less than 1/2 of all test cases pass
  • 0: Does not execute or no specifications met

Program Style

  • 4: Code is well-documented
  • 3: Code has minor documentation errors
    • Has 1 documentation error
  • 2: Code has some documentation errors
    • Has 2-3 documentation errors
  • 1: Code has many documentation errors
    • Has more than 3 documentation errors
  • 0: No apparent attempt to document code

README.txt File

  • 2: README.txt file submitted with specified information included
  • 1: README.txt submitted but some information was not included
  • 0: No README.txt submitted

Total possible: 20, plus extra credit

What to Turn In

Submit your assignment following the instructions for homework. Include the following items for grading:

  1. README.txt file
  2. PostalApp.java (possibly in a JAR file)
  3. Optionally, all the class files in the same JAR file

You must submit all the files needed for your assignment to compile and work correctly. Do not assume that the instructors has any files. Also, do not turn in files that are not part of your assignment, especially ones that do not compile. Your assignment must compile after removing all the .class files and running: javac *.java. In addition, your code must work as submitted.

Home | Blackboard | Announcements | Schedule | Room Policies | Course Info
Help | FAQ's | HowTo's | Links
Last Updated: March 20 2009 @12:20:51