Overview: Postal barcode (Exercise 2.1.36). The initial barcode 1 used by the U.S Postal System to route mail is defined as follows: Each decimal digit in the ZIP code is encoded using a sequence of three half-height and two full-height bars. The barcode starts and ends with a full-height bar (the guard rail) and includes a checksum digit (after the five-digit ZIP code or the nine-digit ZIP+4 code), computed by summing up the original digits modulo 10. Implement the following functions

  • Draw a half-height or full-heigh bar on StdDraw.
  • Given a digit, return the binary code of that digit as a String.
  • Compute the checksum digit.
  • Given a String of 1's and 0s, draw the corresponding barcode in which 1s are full- height bars and 0s are half-height bars. The barcode should be centered in the StdDraw canvas.

Implement a test client that reads in a five or nine digit ZIP code as the command line argument and draws the corresponding postal barcode.

Details

  • Name the program PP2.java.
  • Use the following table to map a digit to barcodes see image.
  • The binary code use 1 for full-height and 0 for half-height bars of the barcode.
  • The width of a bar should be 1/10 of the height of the full-height bar.
  • The space between bars should be the same as the width of a bar.
  • Use an appropriate height to make it easy to see the barcode when displayed (if printed, we would want 24 bars per inch).
  • The checksum digit is the value when added to the sum of the original digits, causes the sum modulo 10 to be zero. Example: digits 0 8 5 4 0 would sum to 17. The checksum would be 3 as (17+3) modulo 10 is zero. Note that this differs from the textbook example of 7.
  • Validate the command line parameters. If invalid values are given then print out a warning message.
  • Your program should display your name and lab CRN at the top of the StdDraw canvas showing the barcode. StdDraw provides a set of functions for writing text to the display.
  • The original Zip code and the calculated checksum digit should be displayed at the bottom of the StdDraw canvas.
  • the barcode should be centered in the middle of the StdDraw canvas.
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.