Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The encoding scheme for a five-digit zip code is shown in Figure 1. There are fu

ID: 3652152 • Letter: T

Question

The encoding scheme for a five-digit zip code is shown in Figure 1. There are full- height frame bars on each side. The five encoded digits are followed by a check digit, which is computed as follows: Add up all digits, and choose the check digit to make the sum a multiple of 10. For example, the zip code 95014 has a sum of 19 (9 + 5 + 0 + 1 + 4), so the check digit is 1 to make the sum equal to 20 (i.e., a multiple of 10).
Each digit of the zip code, and the check digit, is encoded according to the following table, where | denotes a full bar and : a half bar.

1
:::||
2
::|:|
3
::||:
4
:|::|
5
:|:|:
6
?:||::
7
?|:::|
8
?|::|:
9
?|:|::
0
?||:::

Write a program (BarCode.java) that asks the user for a five-digit zip code and prints the bar code. For example (user input underlined):
Please enter a five-digit zip code: 95014
||:|:::|:|:||::::::||:|::|:::|||

Explanation / Answer

import java.util.Scanner;

class BarCode
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
        System.out.print("Enter the 5 digit number: ");
        String b=s.nextLine();
        String ar[]={"||::: ",":::||","::|:|","::||:",":|::|",":|:|:","::||::","||:::|",
                "||::|:","||:|::"};
        int i,sum=0;
        System.out.print("Barcode is: ");
        for(i=0;i<b.length();i++)
        {
            int t=Integer.parseInt(b.charAt(i)+"");
            System.out.print(ar[t]);
            sum=sum+t;
        }
        int sumb=sum;
        while(true)
        {
            if(sum%10==0)break;
            sum++;
        }
        System.out.print(ar[sum-sumb]);
        System.out.println(" Number is: "+b+(sum-sumb));

    }
}

======================================================

Sample output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote