The US postal barcode is used by the US Postal System to rou

The US postal barcode is used by the US Postal System to route mail. Each decimal digit in the zip code is encoded using a sequence of 5 short and long lines for use by scanners as follows: 0: I I s s s (I: long, s: short) 1: s s s I I 2: s s I s I 3: ssI I s 4: s I s s I 5: s I s is 6: s I I s s 7: I s s s I 8: I s s I s 9: I s I s s A sixth checksum digit is appended: it is computed by summing up the original five digits mod 10. In addition, a long line is added to the beginning and appended to the end. Write a program that reads in a five digit zip code and prints the corresponding postal barcode. Print the code horizontally. e g, the following encodes 13210 (with the check digit of 7). 13210 zip code\'s postal barcode is

Solution

Here i am providing code for convertor from zip to barcode :

import java.util.Scanner;
public class Postal
{
    public int digit2;  
    public int digit3;  
    public int digit4;  
    public int digit5;  
    public int digit6;  
    public int checkdigit;
    public static int num;
    public static String temp;
    public static int menu;
    public static int zip;
    public static String code0;
    public static String code1;
    public static String code2;
    public static String code3;
    public static String code4;
    public static String code5;
    public static String code6;
    public static String code7;
    public static String code8;
    public static String code9;
    public static String str;
    public static int numb;
    public Postal()
    {
        zip = 0;

        code0 = \"||:::\"; code1 = \":::||\"; code2 = \"::|:|\";
        code3 = \"::||:\"; code4 = \":|::|\"; code5 = \":|:|:\";
        code6 = \":||::\"; code7 = \"|:::|\"; code8 = \"|::|:\";
       code9 = \"|:|::\";

    }

    public static int getZIP()
    {
        System.out.println(\"Enter a Postal ZIP code : \");
        Scanner sc = new Scanner(System.in);
        zip = sc.nextInt();
        while((zip<01001)||(zip>99950))
        {
            System.out.println(\"**** ERROR ****\");
            System.out.println(\"Entered ZIP code must be between 01001 and 99950\");
            System.out.println(\"Please re-enter the correct zip code: \");
            zip = sc.nextInt();
        }
        return zip;
    }
   public void getDigit(int num)
    {
        digit2 = num/10000;
        digit3 = ((num/1000)-digit2*10);
        digit4 = (num/100 - (digit2*100 + digit3*10));
        digit5 = (num/10 -(digit2*1000 + digit3*100 + digit4*10));
        digit6 = (num - (digit2*10000 + digit3*1000 + digit4*100 + digit5*10));

        checkdigit = 100- (digit2+digit3+digit4+digit5+digit6);
        System.out.println(checkdigit);

        while(checkdigit>10)
        {
            checkdigit -= 10;
         }
        System.out.println(\"**** BARCODE ****\");
        System.out.print(\"|\");
        getBar(digit2);
        getBar(digit3);
        getBar(digit4);
        getBar(digit5);
        getBar(digit6);
        getBar(checkdigit);
        System.out.print(\"|\");

    }
    public void getBar(int x)
    {
        switch(x)
        {
            case 0: System.out.print(code0); break;
            case 1: System.out.print(code1); break;
            case 2: System.out.print(code2); break;
            case 3: System.out.print(code3); break;
            case 4: System.out.print(code4); break;
            case 5: System.out.print(code5); break;
            case 6: System.out.print(code6); break;
            case 7: System.out.print(code7); break;
            case 8: System.out.print(code8); break;
            case 9: System.out.print(code9); break;
        }
    }
    public static void main(String[] args)
    {
        Postal pos = new Postal();
         num = pos.getZIP();
          pos.getDigit(num);
          System.out.println();
       }
}

 The US postal barcode is used by the US Postal System to route mail. Each decimal digit in the zip code is encoded using a sequence of 5 short and long lines f
 The US postal barcode is used by the US Postal System to route mail. Each decimal digit in the zip code is encoded using a sequence of 5 short and long lines f

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site