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

Introduction For faster sorting of letters, the United States Postal Service nco

ID: 3824573 • Letter: I

Question

Introduction For faster sorting of letters, the United States Postal Service ncourages companies that send large volumes of mail to use a bar code denoting the zip code. The encoding scheme for a five-digit zip code is shown in the below figure. There are full-height frame bars (I) one on each side to specify the inning and the end of a bar code for a zip code. In between are the encodings for the five zip code digits and a correction digit, in terms of their weights, 0's or 1's, where 0 is a half-height frame bar and 1 is a full-height frame bar I. For example, for the digit 2, its corresponding wei 00101, which can be represented as in the bar code The correction digit for a given zip code is computed as follows Add up all the digits of a given zip code, then choose the correction digit to make the sum a multiple of 10. For example, the zip code 46805 has a sum of digits of 23, so the correction digit is 7. (n another words, 23 7 30 which is a multiple of 10). Each digit of the zip code and the correction digit are translated into bar-codes according to its wei in the following table igit Weights These data are in an input file called digitWeights.bkt Each 1 denotes a full-height bar and each 0 denotes a half. height bar. Thus, each digit is encoded as a five full- and half-height bars. For example, a 6 is This project to construct a C program which generates a random sequence of 20 zip codes, using srand( creates and displays their corresponding bar-codes. Input Specifications Build an input file contains a data table which depicts the digits 9) and their co rrespond weights, as shown above. to, l Name of this input file as digitWeights.txt". This input file contains 10 rows and six columns. The first column is one of the decimal digits 0 9. The next five columns are the weights containing either 0 or 1

Explanation / Answer

First of all, this question is very big assignment having multiple sub-parts. So, as Chegg recommended, I am solving the part for which program asks the user to enter the ZIP-CODE and produces the barcode for the same .

the code is as follows-

import java.util.Scanner;

public class Postal
{
public int num2;
public int num3;
public int num4;
public int num5;
public int num6;
public int checkDig;
public static int num;
public static String temp;
public static int menu;
public static int zip;
public static String bar0;
public static String bar1;
public static String bar2;
public static String bar3;
public static String bar4;
public static String bar5;
public static String bar6;
public static String bar7;
public static String bar8;
public static String bar9;
public static String str;
public static int numb;

public Postal()
{
zip = 0;

bar0 = "||:::"; bar1 = ":::||"; bar2 = "::|:|";
bar3 = "::||:"; bar4 = ":|::|"; bar5 = ":|:|:";
bar6 = ":||::"; bar7 = "|:::|"; bar8 = "|::|:";
bar9 = "|:|::";

}

public static int getZIP()
{
System.out.println("Please enter a ZIP code : ");
Scanner sc = new Scanner(System.in);
zip = sc.nextInt();
return zip;
}
public static int menu()
{
System.out.println("ZIP-CODE to barcode converter");
System.out.println("Choose one option from following : ");
System.out.println("1) Create ZIP barcode ");
System.out.println("2) Find ZIP code from barcode ");
System.out.println("3) Exit ");
Scanner sc = new Scanner(System.in);
return sc.nextInt();
}

public void getDigit(int num)
{
num2 = num/10000;
num3 = ((num/1000)-num2*10);
num4 = (num/100 - (num2*100 + num3*10));
num5 = (num/10 -(num2*1000 + num3*100 + num4*10));
num6 = (num - (num2*10000 + num3*1000 + num4*100 + num5*10));

checkDig = 100- (num2+num3+num4+num5+num6);
System.out.println(checkDig);

while(checkDig>10)
{ checkDig -= 10; }
System.out.println("**** BARCODE ****");
System.out.print("|");
getBar(num2);
getBar(num3);
getBar(num4);
getBar(num5);
getBar(num6);
getBar(checkDig);
System.out.print("|");

}
public void getBar(int x)
{

switch(x)
{
case 0: System.out.print(bar0); break;
case 1: System.out.print(bar1); break;
case 2: System.out.print(bar2); break;
case 3: System.out.print(bar3); break;
case 4: System.out.print(bar4); break;
case 5: System.out.print(bar5); break;
case 6: System.out.print(bar6); break;
case 7: System.out.print(bar7); break;
case 8: System.out.print(bar8); break;
case 9: System.out.print(bar9); break;
}
}
public static String number()
{
System.out.println("Enter a barcode with using : or | ");
Scanner scn = new Scanner(System.in);
String bar = scn.nextLine();
return bar;
}

public static void getNumber(String temp)
{
System.out.println("");
System.out.println(temp);
if(temp.equals(bar0))
{
       numb = 0;
   }
if(temp.equals(bar1))
{
       numb = 1;
   }
if(temp.equals(bar2))
{
       numb = 2;
   }
if(temp.equals(bar3))
{
       numb = 3;
   }
if(temp.equals(bar4))
{
       numb = 4;
   }
if(temp.equals(bar5))
{
       numb = 5;
   }
if(temp.equals(bar6))
{
       numb = 6;
   }
if(temp.equals(bar7))
{
       numb = 7;
   }
if(temp.equals(bar8))
{
       numb = 8;
   }
if(temp.equals(bar9))
{
       numb = 9;
   }
System.out.print(numb);
}
public static void divide(String temp)
{
Postal po = new Postal();
str = temp.substring(1,6);
po.getNumber(str);
str = temp.substring(6,11);
po.getNumber(str);
str = temp.substring(11,16);
po.getNumber(str);
str = temp.substring(16,21);
po.getNumber(str);
str = temp.substring(21,26);
po.getNumber(str);

}

public static void main(String[] args)
{
Postal pos = new Postal();
while(menu != 3)
{
System.out.println();
menu = pos.menu();
switch (menu)
{
case 1:
num = pos.getZIP();
pos.getDigit(num);
System.out.println();
break;
case 2:
temp = pos.number();
System.out.println(temp);
pos.divide(temp);
break;
case 3:
break;
}
}
}
}

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