SlideShare a Scribd company logo
1 of 11
Download to read offline
I am working on java programming that converts zipcode to barcode and vice versa. I am stuck
in as the instruction requires that I have to use two methods which are getBarcode and
getZipcode to the tester. For this reason, it seems like that I have to call all the methods before
those two methods. However, I think the if statements and swich are not working properly as the
result also is not calling proper results.
Please review what is wrong in this code.
Question: How can I call the methods before getBarcode and getZipcode Question: Is there
anything wrong among switch and if statements?
Question: As the zipcode and barcode should be called as String, Which methods should I use
for changing the Strings into integers?
import java.util.Scanner;
//*********************************
//
// Zipcode class
//
// This is a template for your Zipcode class
// You may add methods and instance variables to this
// class but your code must work with the provided test class ZipTest.java
//
//*********************************
public class Zipcode{
private String zipcode = "";
private String barcode = "";
private static int zip;
private static String str;
public int digit1;
public int digit2;
public int digit3;
public int digit4;
public int digit5;
public int checkDigit;
public static String number;
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 bar0;
public static String temp;
public static int option() {
System.out.println("Enter 1 : Zipcode to Barcode ");
System.out.println("Enter 2 : Barcode to Zipcode ");
Scanner in = new Scanner(System.in);
System.out.println( "Enter the option : " );
return in.nextInt();
}
public Zipcode() {
bar0 = "||:::";
bar1 = ":::||";
bar2 = "::|:|";
bar3 = "::||:";
bar4 = ":|::|";
bar5 = ":|:|:";
bar6 = ":||::";
bar7 = "|:::|";
bar8 = "|::|:";
bar9 = "|:|::";
//barcode concatenates as the loop interates each digit
getBar(digit1);
getBar(digit2);
getBar(digit3);
getBar(digit4);
getBar(digit5);
getBar(checkDigit);
}
public Zipcode(int zip) {
this.getDigit(zip);
}
public void error() {
while((zip<01001) || (zip>99950)) {
System.out.println("Error");
System.out.println("You should enter ZIPCODE between 01001 and 99950");
System.out.println("Please, enter another ZIPCODE");
}
}
public int getDigit(int zip){
int zip = Integer.parseInt(zipcode);
digit1 = zip/10000;
digit2 = ((zip/1000)-digit1*10);
digit3 = (zip/100 - (digit1*100 + digit2*10));
digit4 = (zip/10 -(digit1*1000 + digit2*100 + digit3*10));
digit5 = (zip - (digit1*10000 + digit2*1000 + digit3*100 + digit4*10));
int sum = digit1+digit2+digit3+digit4+digit5;
int checkDigit = (10-(sum%10));
if(checkDigit == 10) {
System.out.println("Check Digit : " + 0);
} else {
System.out.println("Check Digit : " + checkDigit);
}
// add your own code here to
// to complete the constructor
System.out.println("**** BARCODE ****");
return zip;
}
public void getBar(int x) {
switch(x) {
case 0: barcode = bar0 + barcode;
break;
case 1: barcode = bar1 + barcode;
break;
case 2: barcode = bar2 + barcode;
break;
case 3: barcode = bar3 + barcode;
break;
case 4: barcode = bar4 + barcode;
break;
case 5: barcode = bar5 + barcode;
break;
case 6: barcode = bar6 + barcode;
break;
case 7: barcode = bar7 + barcode;
break;
case 8: barcode = bar8 + barcode;
break;
case 9: barcode = bar9 + barcode;
break;
}
barcode = "|" + barcode + "|";
}
// you will need to add more your own methods here
public String getBarcode(){
//leave this method as is
return barcode;
}
//method that changes barcode to Zipcode
public static void divide(String temp) {
Zipcode postal = new Zipcode();
str = temp.substring(0,5);
postal.getZipcode(str);
str = temp.substring(5,10);
postal.getZipcode(str);
str = temp.substring(10,15);
postal.getZipcode(str);
str = temp.substring(15,20);
postal.getZipcode(str);
str = temp.substring(20,25);
postal.getZipcode(str);
}
public String getZip(String temp) {
String number = "";
if( temp.equals(bar1) )
number = number + "0";
if ( temp.equals(bar2) )
number = number +"1";
if( temp.equals(bar3) )
number =number + "2";
if( temp.equals(bar4) )
number = number +"3";
if( temp.equals(bar5) )
number = number +"4";
if( temp.equals(bar6) )
number = number +"5";
if( temp.equals(bar5) )
number = number +"6";
if( temp.equals(bar6) )
number = number +"7";
if( temp.equals(bar7) )
number = number +"8";
if( temp.equals(bar8) )
number = number +"9";
return number;
}
public String getZipcode()
{
return zipcode;
}
}
Solution
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((zip<01001)||(zip>99950))
{
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;
}
}
}
}

More Related Content

Similar to I am working on java programming that converts zipcode to barcode an.pdf

Please follow the code and comments for description and outputs C.pdf
Please follow the code and comments for description and outputs C.pdfPlease follow the code and comments for description and outputs C.pdf
Please follow the code and comments for description and outputs C.pdfproloyankur01
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumlercorehard_by
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programsKaruppaiyaa123
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerAiman Hud
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3Dillon Lee
 
Import java
Import javaImport java
Import javaheni2121
 
OXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IOXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IAbdul Rahman Sherzad
 
AnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdfAnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdfanurag1231
 
Lab Assignment 4 CSE330 Spring 2014 Skeleton Code for ex.docx
 Lab Assignment 4 CSE330 Spring 2014  Skeleton Code for ex.docx Lab Assignment 4 CSE330 Spring 2014  Skeleton Code for ex.docx
Lab Assignment 4 CSE330 Spring 2014 Skeleton Code for ex.docxMARRY7
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxmaxinesmith73660
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming AssignmentCoding Assignment Help
 
The CppCat Analyzer Checks TortoiseGit
The CppCat Analyzer Checks TortoiseGitThe CppCat Analyzer Checks TortoiseGit
The CppCat Analyzer Checks TortoiseGitAndrey Karpov
 
40+ examples of user defined methods in java with explanation
40+ examples of user defined methods in java with explanation40+ examples of user defined methods in java with explanation
40+ examples of user defined methods in java with explanationHarish Gyanani
 
Hi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfHi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfaniyathikitchen
 

Similar to I am working on java programming that converts zipcode to barcode an.pdf (20)

Please follow the code and comments for description and outputs C.pdf
Please follow the code and comments for description and outputs C.pdfPlease follow the code and comments for description and outputs C.pdf
Please follow the code and comments for description and outputs C.pdf
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programs
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
 
5 Rmi Print
5  Rmi Print5  Rmi Print
5 Rmi Print
 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
 
Import java
Import javaImport java
Import java
 
OXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART IOXUS20 JAVA Programming Questions and Answers PART I
OXUS20 JAVA Programming Questions and Answers PART I
 
07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt
 
AnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdfAnswerNote Provided code shows several bugs, hence I implemented.pdf
AnswerNote Provided code shows several bugs, hence I implemented.pdf
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
PSI 3 Integration
PSI 3 IntegrationPSI 3 Integration
PSI 3 Integration
 
Lab Assignment 4 CSE330 Spring 2014 Skeleton Code for ex.docx
 Lab Assignment 4 CSE330 Spring 2014  Skeleton Code for ex.docx Lab Assignment 4 CSE330 Spring 2014  Skeleton Code for ex.docx
Lab Assignment 4 CSE330 Spring 2014 Skeleton Code for ex.docx
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming Assignment
 
The CppCat Analyzer Checks TortoiseGit
The CppCat Analyzer Checks TortoiseGitThe CppCat Analyzer Checks TortoiseGit
The CppCat Analyzer Checks TortoiseGit
 
40+ examples of user defined methods in java with explanation
40+ examples of user defined methods in java with explanation40+ examples of user defined methods in java with explanation
40+ examples of user defined methods in java with explanation
 
Mcq cpup
Mcq cpupMcq cpup
Mcq cpup
 
Hi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfHi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdf
 

More from thangarajarivukadal

Which of the following is not a high-speed Internet assess service.pdf
Which of the following is not a high-speed Internet assess service.pdfWhich of the following is not a high-speed Internet assess service.pdf
Which of the following is not a high-speed Internet assess service.pdfthangarajarivukadal
 
Write a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdfWrite a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdfthangarajarivukadal
 
Which of the following describes silver A material that has a low r.pdf
Which of the following describes silver  A material that has a low r.pdfWhich of the following describes silver  A material that has a low r.pdf
Which of the following describes silver A material that has a low r.pdfthangarajarivukadal
 
why dont most other types of bacteria produce ulcers ( like helico.pdf
why dont most other types of bacteria produce ulcers ( like helico.pdfwhy dont most other types of bacteria produce ulcers ( like helico.pdf
why dont most other types of bacteria produce ulcers ( like helico.pdfthangarajarivukadal
 
You will construct a manual for your company that defines the Risk M.pdf
You will construct a manual for your company that defines the Risk M.pdfYou will construct a manual for your company that defines the Risk M.pdf
You will construct a manual for your company that defines the Risk M.pdfthangarajarivukadal
 
Which of the following statements about DNA and RNA are true, and wh.pdf
Which of the following statements about DNA and RNA are true, and wh.pdfWhich of the following statements about DNA and RNA are true, and wh.pdf
Which of the following statements about DNA and RNA are true, and wh.pdfthangarajarivukadal
 
You observe a cell switch from performing cellular respiration to per.pdf
You observe a cell switch from performing cellular respiration to per.pdfYou observe a cell switch from performing cellular respiration to per.pdf
You observe a cell switch from performing cellular respiration to per.pdfthangarajarivukadal
 
You are speaking to a group of high school students in a technology .pdf
You are speaking to a group of high school students in a technology .pdfYou are speaking to a group of high school students in a technology .pdf
You are speaking to a group of high school students in a technology .pdfthangarajarivukadal
 
Who might use financial statements List at least 3 examples of like.pdf
Who might use financial statements List at least 3 examples of like.pdfWho might use financial statements List at least 3 examples of like.pdf
Who might use financial statements List at least 3 examples of like.pdfthangarajarivukadal
 
What could be the rational for IRC exempting income from bonds issue.pdf
What could be the rational for IRC exempting income from bonds issue.pdfWhat could be the rational for IRC exempting income from bonds issue.pdf
What could be the rational for IRC exempting income from bonds issue.pdfthangarajarivukadal
 
Tropical forests are extremely important ecosystems on the planet. Ho.pdf
Tropical forests are extremely important ecosystems on the planet. Ho.pdfTropical forests are extremely important ecosystems on the planet. Ho.pdf
Tropical forests are extremely important ecosystems on the planet. Ho.pdfthangarajarivukadal
 
We learn of the the black dwarf, the final stage in a death of a low.pdf
We learn of the the black dwarf, the final stage in a death of a low.pdfWe learn of the the black dwarf, the final stage in a death of a low.pdf
We learn of the the black dwarf, the final stage in a death of a low.pdfthangarajarivukadal
 
What are the main responsibilities of the Network Layer What are th.pdf
What are the main responsibilities of the Network Layer What are th.pdfWhat are the main responsibilities of the Network Layer What are th.pdf
What are the main responsibilities of the Network Layer What are th.pdfthangarajarivukadal
 
These organs in spiders produce with In this kind of circulato.pdf
These organs in spiders produce with  In this kind of circulato.pdfThese organs in spiders produce with  In this kind of circulato.pdf
These organs in spiders produce with In this kind of circulato.pdfthangarajarivukadal
 
Ensign Danielle Anderson returned from a Qualified Hazardous Duty Ar.pdf
Ensign Danielle Anderson returned from a Qualified Hazardous Duty Ar.pdfEnsign Danielle Anderson returned from a Qualified Hazardous Duty Ar.pdf
Ensign Danielle Anderson returned from a Qualified Hazardous Duty Ar.pdfthangarajarivukadal
 
Oxidation and reduction states are relatively easy to determine for m.pdf
Oxidation and reduction states are relatively easy to determine for m.pdfOxidation and reduction states are relatively easy to determine for m.pdf
Oxidation and reduction states are relatively easy to determine for m.pdfthangarajarivukadal
 
Question 9 (1 point) What is data visualization O Making a mental no.pdf
Question 9 (1 point) What is data visualization O Making a mental no.pdfQuestion 9 (1 point) What is data visualization O Making a mental no.pdf
Question 9 (1 point) What is data visualization O Making a mental no.pdfthangarajarivukadal
 
Q i.Why is it, in general the fracture toughness of ductile material.pdf
Q i.Why is it, in general the fracture toughness of ductile material.pdfQ i.Why is it, in general the fracture toughness of ductile material.pdf
Q i.Why is it, in general the fracture toughness of ductile material.pdfthangarajarivukadal
 
Problem 1. Think about an individual that you are investigating from .pdf
Problem 1. Think about an individual that you are investigating from .pdfProblem 1. Think about an individual that you are investigating from .pdf
Problem 1. Think about an individual that you are investigating from .pdfthangarajarivukadal
 
Junior collects baseball cards. He owns one Felix Hernandez card tha.pdf
Junior collects baseball cards. He owns one Felix Hernandez card tha.pdfJunior collects baseball cards. He owns one Felix Hernandez card tha.pdf
Junior collects baseball cards. He owns one Felix Hernandez card tha.pdfthangarajarivukadal
 

More from thangarajarivukadal (20)

Which of the following is not a high-speed Internet assess service.pdf
Which of the following is not a high-speed Internet assess service.pdfWhich of the following is not a high-speed Internet assess service.pdf
Which of the following is not a high-speed Internet assess service.pdf
 
Write a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdfWrite a program to implement below operations with both singly and d.pdf
Write a program to implement below operations with both singly and d.pdf
 
Which of the following describes silver A material that has a low r.pdf
Which of the following describes silver  A material that has a low r.pdfWhich of the following describes silver  A material that has a low r.pdf
Which of the following describes silver A material that has a low r.pdf
 
why dont most other types of bacteria produce ulcers ( like helico.pdf
why dont most other types of bacteria produce ulcers ( like helico.pdfwhy dont most other types of bacteria produce ulcers ( like helico.pdf
why dont most other types of bacteria produce ulcers ( like helico.pdf
 
You will construct a manual for your company that defines the Risk M.pdf
You will construct a manual for your company that defines the Risk M.pdfYou will construct a manual for your company that defines the Risk M.pdf
You will construct a manual for your company that defines the Risk M.pdf
 
Which of the following statements about DNA and RNA are true, and wh.pdf
Which of the following statements about DNA and RNA are true, and wh.pdfWhich of the following statements about DNA and RNA are true, and wh.pdf
Which of the following statements about DNA and RNA are true, and wh.pdf
 
You observe a cell switch from performing cellular respiration to per.pdf
You observe a cell switch from performing cellular respiration to per.pdfYou observe a cell switch from performing cellular respiration to per.pdf
You observe a cell switch from performing cellular respiration to per.pdf
 
You are speaking to a group of high school students in a technology .pdf
You are speaking to a group of high school students in a technology .pdfYou are speaking to a group of high school students in a technology .pdf
You are speaking to a group of high school students in a technology .pdf
 
Who might use financial statements List at least 3 examples of like.pdf
Who might use financial statements List at least 3 examples of like.pdfWho might use financial statements List at least 3 examples of like.pdf
Who might use financial statements List at least 3 examples of like.pdf
 
What could be the rational for IRC exempting income from bonds issue.pdf
What could be the rational for IRC exempting income from bonds issue.pdfWhat could be the rational for IRC exempting income from bonds issue.pdf
What could be the rational for IRC exempting income from bonds issue.pdf
 
Tropical forests are extremely important ecosystems on the planet. Ho.pdf
Tropical forests are extremely important ecosystems on the planet. Ho.pdfTropical forests are extremely important ecosystems on the planet. Ho.pdf
Tropical forests are extremely important ecosystems on the planet. Ho.pdf
 
We learn of the the black dwarf, the final stage in a death of a low.pdf
We learn of the the black dwarf, the final stage in a death of a low.pdfWe learn of the the black dwarf, the final stage in a death of a low.pdf
We learn of the the black dwarf, the final stage in a death of a low.pdf
 
What are the main responsibilities of the Network Layer What are th.pdf
What are the main responsibilities of the Network Layer What are th.pdfWhat are the main responsibilities of the Network Layer What are th.pdf
What are the main responsibilities of the Network Layer What are th.pdf
 
These organs in spiders produce with In this kind of circulato.pdf
These organs in spiders produce with  In this kind of circulato.pdfThese organs in spiders produce with  In this kind of circulato.pdf
These organs in spiders produce with In this kind of circulato.pdf
 
Ensign Danielle Anderson returned from a Qualified Hazardous Duty Ar.pdf
Ensign Danielle Anderson returned from a Qualified Hazardous Duty Ar.pdfEnsign Danielle Anderson returned from a Qualified Hazardous Duty Ar.pdf
Ensign Danielle Anderson returned from a Qualified Hazardous Duty Ar.pdf
 
Oxidation and reduction states are relatively easy to determine for m.pdf
Oxidation and reduction states are relatively easy to determine for m.pdfOxidation and reduction states are relatively easy to determine for m.pdf
Oxidation and reduction states are relatively easy to determine for m.pdf
 
Question 9 (1 point) What is data visualization O Making a mental no.pdf
Question 9 (1 point) What is data visualization O Making a mental no.pdfQuestion 9 (1 point) What is data visualization O Making a mental no.pdf
Question 9 (1 point) What is data visualization O Making a mental no.pdf
 
Q i.Why is it, in general the fracture toughness of ductile material.pdf
Q i.Why is it, in general the fracture toughness of ductile material.pdfQ i.Why is it, in general the fracture toughness of ductile material.pdf
Q i.Why is it, in general the fracture toughness of ductile material.pdf
 
Problem 1. Think about an individual that you are investigating from .pdf
Problem 1. Think about an individual that you are investigating from .pdfProblem 1. Think about an individual that you are investigating from .pdf
Problem 1. Think about an individual that you are investigating from .pdf
 
Junior collects baseball cards. He owns one Felix Hernandez card tha.pdf
Junior collects baseball cards. He owns one Felix Hernandez card tha.pdfJunior collects baseball cards. He owns one Felix Hernandez card tha.pdf
Junior collects baseball cards. He owns one Felix Hernandez card tha.pdf
 

Recently uploaded

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 

Recently uploaded (20)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 

I am working on java programming that converts zipcode to barcode an.pdf

  • 1. I am working on java programming that converts zipcode to barcode and vice versa. I am stuck in as the instruction requires that I have to use two methods which are getBarcode and getZipcode to the tester. For this reason, it seems like that I have to call all the methods before those two methods. However, I think the if statements and swich are not working properly as the result also is not calling proper results. Please review what is wrong in this code. Question: How can I call the methods before getBarcode and getZipcode Question: Is there anything wrong among switch and if statements? Question: As the zipcode and barcode should be called as String, Which methods should I use for changing the Strings into integers? import java.util.Scanner; //********************************* // // Zipcode class // // This is a template for your Zipcode class // You may add methods and instance variables to this // class but your code must work with the provided test class ZipTest.java // //********************************* public class Zipcode{ private String zipcode = ""; private String barcode = ""; private static int zip; private static String str; public int digit1; public int digit2; public int digit3; public int digit4; public int digit5; public int checkDigit; public static String number;
  • 2. 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 bar0; public static String temp; public static int option() { System.out.println("Enter 1 : Zipcode to Barcode "); System.out.println("Enter 2 : Barcode to Zipcode "); Scanner in = new Scanner(System.in); System.out.println( "Enter the option : " ); return in.nextInt(); } public Zipcode() { bar0 = "||:::"; bar1 = ":::||"; bar2 = "::|:|"; bar3 = "::||:"; bar4 = ":|::|"; bar5 = ":|:|:"; bar6 = ":||::"; bar7 = "|:::|"; bar8 = "|::|:"; bar9 = "|:|::"; //barcode concatenates as the loop interates each digit getBar(digit1);
  • 3. getBar(digit2); getBar(digit3); getBar(digit4); getBar(digit5); getBar(checkDigit); } public Zipcode(int zip) { this.getDigit(zip); } public void error() { while((zip<01001) || (zip>99950)) { System.out.println("Error"); System.out.println("You should enter ZIPCODE between 01001 and 99950"); System.out.println("Please, enter another ZIPCODE"); } } public int getDigit(int zip){ int zip = Integer.parseInt(zipcode); digit1 = zip/10000; digit2 = ((zip/1000)-digit1*10); digit3 = (zip/100 - (digit1*100 + digit2*10)); digit4 = (zip/10 -(digit1*1000 + digit2*100 + digit3*10)); digit5 = (zip - (digit1*10000 + digit2*1000 + digit3*100 + digit4*10)); int sum = digit1+digit2+digit3+digit4+digit5; int checkDigit = (10-(sum%10)); if(checkDigit == 10) { System.out.println("Check Digit : " + 0); } else { System.out.println("Check Digit : " + checkDigit); } // add your own code here to // to complete the constructor System.out.println("**** BARCODE ****"); return zip;
  • 4. } public void getBar(int x) { switch(x) { case 0: barcode = bar0 + barcode; break; case 1: barcode = bar1 + barcode; break; case 2: barcode = bar2 + barcode; break; case 3: barcode = bar3 + barcode; break; case 4: barcode = bar4 + barcode; break; case 5: barcode = bar5 + barcode; break; case 6: barcode = bar6 + barcode; break; case 7: barcode = bar7 + barcode; break; case 8: barcode = bar8 + barcode; break; case 9: barcode = bar9 + barcode; break; } barcode = "|" + barcode + "|"; } // you will need to add more your own methods here public String getBarcode(){ //leave this method as is return barcode; } //method that changes barcode to Zipcode public static void divide(String temp) {
  • 5. Zipcode postal = new Zipcode(); str = temp.substring(0,5); postal.getZipcode(str); str = temp.substring(5,10); postal.getZipcode(str); str = temp.substring(10,15); postal.getZipcode(str); str = temp.substring(15,20); postal.getZipcode(str); str = temp.substring(20,25); postal.getZipcode(str); } public String getZip(String temp) { String number = ""; if( temp.equals(bar1) ) number = number + "0"; if ( temp.equals(bar2) ) number = number +"1"; if( temp.equals(bar3) ) number =number + "2"; if( temp.equals(bar4) ) number = number +"3"; if( temp.equals(bar5) ) number = number +"4"; if( temp.equals(bar6) ) number = number +"5"; if( temp.equals(bar5) ) number = number +"6"; if( temp.equals(bar6) ) number = number +"7"; if( temp.equals(bar7) ) number = number +"8"; if( temp.equals(bar8) ) number = number +"9"; return number;
  • 6. } public String getZipcode() { return zipcode; } } Solution 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()
  • 7. { 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((zip<01001)||(zip>99950)) { 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));
  • 8. 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);
  • 9. 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))
  • 10. { 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) {
  • 11. 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; } } } }