8 points
The post office uses a scheme for converting a zip code, such as 08840, into a bar code. In this program you do the conversion.
Here is how the post office's conversion scheme works. Each digit of a zip code is converted into either a tall bar or a short bar. In this program, we'll use | for a tall bar and : for a short bar. For example, a '1' in a zip code is converted into ':::||'.
A 6th digit, called a 'correction digit', is also displayed in the bar code. The java file explains this.
Here is the table that the post office uses to convert the digits 0 to 9 into tall bars and short bars:
| Digit | Bar Code version |
| 0 | ||::: |
| 1 | :::|| |
| 2 | ::|:| |
| 3 | ::||: |
| 4 | :|::| |
| 5 | :|:|: |
| 6 | :||:: |
| 7 | |:::| |
| 8 | |::|: |
| 9 | |:|:: |
Here is sample output from this program:
The Java file has explanations on how to write the different methods.
You can download BarCode.java to use as a starting point in writing your program.
This programming assignment is based directly on Exercise P7.11 in Computing Concepts with Java Essentials, Third Edition, by Cay Horstmann.