Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Homework 3 - Bar Codes Java 1 Description The Zone Improvement Plan (ZIP) Code is used by the Postal Service to efficiently deliver mail. For

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Homework 3 - Bar Codes Java 1 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 below 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 likeI where the colon (:) is the half-bar and the pipe (I) is the full-bar. The symbol (:| 1) represents the number 1. The table below shows the representation for each number Di Bar 1 Bar 2 Bar 3 Bar 4 Bar 5 0 0 0 0 0 0 0 0 Note, the O represents the half-bar colon (: and the 1 is the full-bar pipe (I) 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 Again, considering the example from above we can determine the zip code and the check digit. Digit 1-] | which maps 00011 from the table above the digit 1 Digit 2-I:1 which maps to 00101 from the table above the digit - 2 Digit 3 -:1I: which maps to 00110 from the table above the digit -3 Digit 4 - :::| which maps to 01001 from the table above the digit 4 Digit 5 -l:l: which maps to 01010 from the table above the digit-5 Sum 1+ 2+ 3+4 + 5-15. The next multiple of 10 is 20 so the check digit is 5. Check digit Notice from the image above the last six symbols are ::: if you remove the last full-bar (Remember the entire code is demarcated by full-bars) you have the symbol:: which is the symbol for 5 (the check digit)! The other symbols are for the extended 4-digit code we use today. For the purpose of this assignment, we will only consider the 5-digit code. 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: Decode a bar code Encode a zip code a. b. 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 (I) for full bars. Remember 5 symbols per digit with a check digit and the demarcating full-bars. 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? b. 4. If the user chooses to encode a zip code 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). a. b. Also, display the calculated check digit showing the math is correct Consider something like Sum of digits is 14. 14 620 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 int getlnteger(String prompt)// get an integer from the user using the given prompt. int getlnteger(String prompt, int min, int max) // get an integer from the user with the given prompt within the given range min and max inclusive a. b. c. String encodeDigit(int digit)// given a digit get the symbol for that digit, d. String encodeZipCode(int zipCode)// given the zip code, return the entire bar e. int decodeSymbol(String symbol)// given a symbol like, return the f. int decodeBarCode(String barCode)// given the entire bar code, return the 5- example I would return :::I I code for the zip code - should be 32 chars long integer value. So:1 1 should return 1. g. h. i. digit bar code int sumDigits(int number)// given a number, return the sum of the digits. int getCheckDigit(int sum)// given a sum, return the check digit for that sum. Int getCheckDigit (String barCode)// given a full bar code, return the check digit. 7. Do not forget the Javadoo 8. NOTE DO NOT manipulate the zip code integers as a string. Make sure you accept the zip code as an integer and parse it as an integer. Hint - use a combination of the mod (%) and / operator to pull the zip code apart. You should not be converting the integer to a string to manipulate it, keep it as an integer Homework 3 - Bar Codes Java 1 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 below 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 likeI where the colon (:) is the half-bar and the pipe (I) is the full-bar. The symbol (:| 1) represents the number 1. The table below shows the representation for each number Di Bar 1 Bar 2 Bar 3 Bar 4 Bar 5 0 0 0 0 0 0 0 0 Note, the O represents the half-bar colon (: and the 1 is the full-bar pipe (I) 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 Again, considering the example from above we can determine the zip code and the check digit. Digit 1-] | which maps 00011 from the table above the digit 1 Digit 2-I:1 which maps to 00101 from the table above the digit - 2 Digit 3 -:1I: which maps to 00110 from the table above the digit -3 Digit 4 - :::| which maps to 01001 from the table above the digit 4 Digit 5 -l:l: which maps to 01010 from the table above the digit-5 Sum 1+ 2+ 3+4 + 5-15. The next multiple of 10 is 20 so the check digit is 5. Check digit Notice from the image above the last six symbols are ::: if you remove the last full-bar (Remember the entire code is demarcated by full-bars) you have the symbol:: which is the symbol for 5 (the check digit)! The other symbols are for the extended 4-digit code we use today. For the purpose of this assignment, we will only consider the 5-digit code. 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: Decode a bar code Encode a zip code a. b. 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 (I) for full bars. Remember 5 symbols per digit with a check digit and the demarcating full-bars. 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? b. 4. If the user chooses to encode a zip code 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). a. b. Also, display the calculated check digit showing the math is correct Consider something like Sum of digits is 14. 14 620 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 int getlnteger(String prompt)// get an integer from the user using the given prompt. int getlnteger(String prompt, int min, int max) // get an integer from the user with the given prompt within the given range min and max inclusive a. b. c. String encodeDigit(int digit)// given a digit get the symbol for that digit, d. String encodeZipCode(int zipCode)// given the zip code, return the entire bar e. int decodeSymbol(String symbol)// given a symbol like, return the f. int decodeBarCode(String barCode)// given the entire bar code, return the 5- example I would return :::I I code for the zip code - should be 32 chars long integer value. So:1 1 should return 1. g. h. i. digit bar code int sumDigits(int number)// given a number, return the sum of the digits. int getCheckDigit(int sum)// given a sum, return the check digit for that sum. Int getCheckDigit (String barCode)// given a full bar code, return the check digit. 7. Do not forget the Javadoo 8. NOTE DO NOT manipulate the zip code integers as a string. Make sure you accept the zip code as an integer and parse it as an integer. Hint - use a combination of the mod (%) and / operator to pull the zip code apart. You should not be converting the integer to a string to manipulate it, keep it as an integer

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions

Question

find all matrices A (a) A = 13 (b) A + A = 213

Answered: 1 week ago

Question

Why We Form Relationships Managing Relationship Dynamics?

Answered: 1 week ago