Answered Essay: frame bars digit 1 digit 2 digit 3 digit 4 digit 5 check digit Figure 2. Encoding for Five-Digit Bar Codes

For faster sorting of letters, the United States Postal Service encourages 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 figure 2. The five encoded digits are followed by a correction digit, which is computed as follows: Add up all the digits, and choose the correction digit to make the sum a multiple of 10. For example, the ZIP code 95014 has a sum of digits 19, so the correction digit is 1 to make the sum equal to 20

frame bars digit 1 digit 2 digit 3 digit 4 digit 5 check digit Figure 2. Encoding for Five-Digit Bar CodesFigure 2. Encoding for Five-Digit Bar Codes

Each digit of the ZIP code, and the correction digit, is encoded according to the following table:

The digit cab be easily computed from the bar code using the column weights 7, 4, 2, 1, 0. For example, 01100 is 0 x 7 + 1 x 4 + 1 x 2 + 0 x 1 + 0 x 0 = 6.
The only exception is 0, which would yield 11 according to the weight formula.
Write a program that asks the user for a zip code and prints the bar code. Use : for half bars, | for full bars.

For example, 95014 becomes

||:|:::|:|:||::::::||:|::|:::|||

Provide these methods:
public static void printDigit(int d) //This method takes one integer digit only, and outputs its value in barcode public static void printBarCode(int zipCode) //This method takes the zipcode and prints the complete bar code You can add other methods as needed

Write the method that reads in a bar code (with : denoting half bars and | denoting full bars) and prints out the zip code it represents. Print an error message if the bar code is not correct.

Write the code with a menu asking the user to select between reading the bar code, reading the zip code “be careful, the zipcode can not start with a zero”, or exit the program.

When the user selects one of the first two options the user should select between entering the bar/zip code (based on the selection from the previous menu) and using a randomly generated one.

The code should repeat until the user selects to exit. Your code should validate the user’s entry for the menu.

Upload your documented code to BeachBoard with sample runs, and demonstrate in class. Print one page only –The other file

It is important to have method calls in main, besides some important code lines.

*** Please help me with my code, this is what I have so far but I am trying to put this in a while loop so it will keep asking the user to input zip code and brcode until they hit like 2 and it stops. this is the list of things i need to change:

□ Repeats until user chose to exit

□ Validate entry

□ Submenu

Functions (4 points each)

□ public static void printDigit(int d)

□ public static void printBarCode(int zipCode)

□ Random generator usage(Could be a standalone function or not)

□ Valid correction digit (Could be a standalone function or not)

General

□ Documentation (5 points) o Comments

o General Name & Description

o For every function □ Output (4 points)

o Multiple based on the menu

frame bars digit 1 digit 2 digit 3 digit 4 digit 5 check digit Figure 2. Encoding for Five-Digit Bar Codes

Expert Answer

 

Note:- Changed the main method to include a flag that will be checked in while condition.

import java.util.*;
import java.lang.String;

public class barcode {
public static String [] bars = {“||:::”,”:::||”, “::|:|”, “::||:”, “:|::|”, “:|:|:”, “:||::”,”|:::|”, “|::|:”, “|:|::” };

public static int find_digit(String str) {
switch(str)
{
case “||:::”:
return 0;
case “:::||”:
return 1;
case “::|:|”:
return 2;
case “::||:”:
return 3;
case “:|::|”:
return 4;
case “:|:|:”:
return 5;
case “:||::”:
return 6;
case “|:::|”:
return 7;
case “|::|:”:
return 8;
case “|:|::”:
return 9;
default:
return -1;
}
}

public static void ConvertBar(int ss)
{
if(ss<10000 || ss>99999)
{
System.out.println(“Zip Code does not exist”);
return;
}
StringBuffer barC = new StringBuffer(“|”);
int rev =0;
while (ss != 0)
{
rev = rev*10 + ss % 10;
ss /= 10;
}
int total = 0;
while(rev!=0)
{
barC.append(bars[rev%10]);
total = total+(rev%10);
rev/=10;
}
if(20-total>=10)
{
System.out.println(“Zip Code does not exist”);
return;
}
barC.append(bars[20-total]);
barC.append(“|”);
System.out.print(“This zipcode is equivalant to: “);
System.out.println(barC);
}

public static void ConvertZip(String ss1)
{
int zip = 0;
int n = ss1.length();
if(n!=32)
{
System.out.println(“Zip Code does not exist”);
return;
}
int cnt=0;
for(int i=1;cnt<5;i+=5,cnt++)
{
zip = zip*10;
int x = find_digit(ss1.substring(i,i+5));
if(x==-1)
{
System.out.println(“Zip Code does not exist”);
return;
}
zip = zip + x;
}
System.out.print(“Corresponding Zipcode : “);
System.out.println(zip);
}
public static void main(String[] args) {
int flag=1; //add a flag to check whether the user has selected exit option
while(flag==1){
System.out.println(“Press 0 to convert zipcode to barcode”);
System.out.println(“Press 1 to convert barcode to zipcode”);
System.out.println(“Press 2 to exit”);
Scanner s =new Scanner(System.in);
int c = s.nextInt();
switch(c)
{
case 0:
Scanner s2 =new Scanner(System.in);
System.out.println(“Enter Zipcode”);
int ss = s2.nextInt();
ConvertBar(ss);
break;
case 1:
Scanner s3 =new Scanner(System.in);
System.out.println(“Enter Barcode”);
String ss1 = s3.nextLine();
ConvertZip(ss1);
break;
case 2:
Scanner s4 =new Scanner(System.in);
int ss2 = s4.nextInt();
flag=0;
break;

default:
System.out.println(“Not available!!”);
}
}
}
}

OUTPUT:

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.