Reference no: EM132238867
Homework - Bar Codes
Description - The Zone Improvement Plan (ZIP) Code is used by the Postal Service to efficiently deliver mail. For this assignment, we will only consider the first iteration, 5-digit zip code. The zip code can be encoded into a bar code like the one in attached file.
The bar code consists of groups of 5 symbols. Each 5-symbol group represents a number. The bar code has 32 symbols, so it represents a 6-digit number demarcated by a starting | and a closing |. The six digits represent the 5-dight zip code and the check digit which is always placed at the end. Consider the example above. The first symbol | is ignored, as is the last. So, the first five symbols are three half-bars followed by two full-bars. We can write it like - :::|| where the colon (:) is the half-bar and the pipe (|) is the full-bar. The symbol (:::||) represents the number 1. The table below shows the representation for each number.
Digit
|
Bar 1
|
Bar 2
|
Bar 3
|
Bar 4
|
Bar 5
|
1
|
0
|
0
|
0
|
1
|
1
|
2
|
0
|
0
|
1
|
0
|
1
|
3
|
0
|
0
|
1
|
1
|
0
|
4
|
0
|
1
|
0
|
0
|
1
|
5
|
0
|
1
|
0
|
1
|
0
|
6
|
0
|
1
|
1
|
0
|
0
|
7
|
1
|
0
|
0
|
0
|
1
|
8
|
1
|
0
|
0
|
1
|
0
|
9
|
1
|
0
|
1
|
0
|
0
|
0
|
1
|
1
|
0
|
0
|
0
|
Note, the 0 represents the half-bar colon (:) and the 1 is the full-bar pipe (|).
As you can see the symbol :::|| would match the digit 1.
To calculate the check digit, sum all digits of the 5-digit code and choose a check digit which would make the sum a multiple of 10.
Specifications - You will need to complete the following:
1. Create a new project and add a class Code.
2. You will allow the user to select one of two options:
a. Decode a bar code
b. Encode a zip code
3. If the user chooses to decode a bar code
a. Prompt the user for the bar code - 32 chars long with colons (:) for half-bars and pipes (|) for full bars. Remember 5 symbols per digit with a check digit and the demarcating full-bars.
b. Display the decoded bar code as the 5-digit zip code and separately the check digit. Also, display if the zip code is correct. Does the check digit match what is should be?
4. If the user chooses to encode a zip code
a. Prompt the user for the 5-digit zip code (as an integer) and display the full bar code with the demarcating full-bars and the check digit (all 32 chars).
b. Also, display the calculated check digit showing the math is correct - Consider something like:
Sum of digits is 14.
14 + 6 = 20
Therefore, the check digit is 6.
5. DO NOT assume the user will enter valid data. When asking for a zip code, be sure to check it is a positive integer value. When asking for the bar code, be sure it is only 32 chars long and only contains the colon and pipe symbols.
6. You will need to create the following methods to solve the problem. Each method must be implemented.
a. int getInteger(String prompt) // get an integer from the user using the given prompt.
b. int getInteger(String prompt, int min, int max) // get an integer from the user with the given prompt within the given range - min and max inclusive.
c. String encodeDigit(int digit) // given a digit get the symbol for that digit, example 1 would return :::||
d. String encodeZipCode(int zipCode) // given the zip code, return the entire bar code for the zip code - should be 32 chars long.
e. int decodeSymbol(String symbol) // given a symbol like :::||, return the integer value. So :::|| should return 1.
f. int decodeBarCode(String barCode) // given the entire bar code, return the 5- digit bar code.
g. int sumDigits(int number) // given a number, return the sum of the digits.
h. int getCheckDigit(int sum) // given a sum, return the check digit for that sum.
i. Int getCheckDigit(String barCode) // given a full bar code, return the check digit.
7. Do not forget the Javadoc
Documentation - You will create one document.
A text document (.docx, .rtf, .pdf) which contains the following:
Your name and assignment.
A screenshot of your code output for three different test runs of each option: encode and decode. These are your main test cases.
You will also need to show each method works as expected. These are method test cases. Write code that tests each method and shows they work as expected. Each method needs three test cases. Show a screenshot of the method test cases.
You also need to explain in detail the following:
- What is the importance of writing your own JavaDoc?
- Explain the parts of each JavaDoc block.
- What is method overloading? What abstract programming concept does it represent?
Remember to be specific in your responses.
Attachment:- Assignment File.rar