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

I\'m provided with the test class ZipTest.java The class you will write, Zipcode

ID: 3592156 • Letter: I

Question

I'm provided with the test class ZipTest.java

The class you will write, Zipcode.java, should work with the test class.

The question has two parts : Zipcode to Barcode and vice-versa Barcode to Zipcode

Please HELPPP with complete amd correct answer

P8.6 For faster sorting of letters, the U.S. Postal Service encourages companies that send large volumes of mail to use a bar code denoting the ZIP code (see Figure 8) The encoding scheme for a five-digit ZIP code is shown in Figure 9. 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 ECRLOT CO57 CODE C671RTS2 JOHN DOE 1009 FRANKLIN BLVD SUNNYVALE Frame bars CO57 CA 95014 5143 iDit Digit 1 Digit 2 Digit 3 Digit 4 Digit 5 Check Figure 8 A Postal Bar Code Figure 9 Encoding for Five-Digit Bar Codes ter 8 Designing Classes make the sum a multiple of 10. For example, the sum of the digits in the ZIP code 95014 is 19, so the check digit is 1 to make the sum equal to 20 Each digit of the ZIP code, and the check digit, is encoded according to the table at right, where 0 denotes a half bar and 1 a full bar. Note that thev represent all combinations of two full and three half bars. The digit can be computed easily from the bar code using the column weights 7,4,2,1,0. For example, 01100 is Weight 7 4 2 10 0 0 0 1 1 Digit 0x7+1x4+1x2+0x1+0x0-6 4 The only exception is 0, which would yield 11 according to the weight formula. Write a program that asks the user for aZIP code and prints the bar code. Use: for half bars, | for full bars. For example, 95014 becones 1 010 0 (Alternatively, write a graphical application that draws real bars.) Your program should also be able to carry out the opposite conversion: Translate bars into their ZIP code, reporting any errors in the input format or a mismatch of the digits

Explanation / Answer

//Postal.java - Jimmy Kurian import java.util.Scanner; public class Postal { public int num2; // 10000 digit public int num3; // 1000 digit public int num4; // 100 digit public int num5; // 10 digit public int num6; // 1 digit public int checkDig; // check digit 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("Enter a ZIP code : "); Scanner sc = new Scanner(System.in); zip = sc.nextInt(); while((zip99950)) { System.out.println("**** ERROR ****"); System.out.println("The ZIP code must be between 01001 and 99950"); System.out.println("Please,enter the correct zip : "); zip = sc.nextInt(); } return zip; } public static int menu() { System.out.println("**** Zip & Bar Code Convertor ****"); 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; } } } }