Question
Using Java (Eclipse) Numbers in Text File: 12345 33199 20500 10001 99950 00501 Can someone please help me with why this code is not working?
Using Java (Eclipse)
Numbers in Text File:
12345
33199
20500
10001
99950
00501
Can someone please help me with why this code is not working?
Please ask specific questions if you do not understand what I'm trying to do and not just (need more information).
**I am trying to verify ZIP Codes inputted into my tax file and then asked the user to input a ZIP Code. Then tell them if it's a valid ZIP Code or not based on what's in my tax file. I have created a loop to ask them to enter another one if they want to and have created a way to exit the code. If the zip code is valid, it needs to display the barcode and then ask if the user wants to enter another. **
-----------------------------------------------
package Barcode;
import java.util.Scanner;
import java.io.IOException;
import java.io.File;
public class barcodeMain {
// A method called "vaildator" that accepts an zip-code as its argument & returns a Boolean
static int vaildZipCodes[];
public static boolean validator(String acNm) {
for (int w = 0; w vaildZipCodes.length; w++) {
if (Integer.parseInt(acNm) == vaildZipCodes[w]) {
return true;
}
}
// Must return false in order to check if number is valid
return false;
}
private static int calcZip(String barCode) {
int zip = 0;
for(int i=1; i String bar = barCode.substring(i,i+5); //System.out.println(bar); if(bar.equals("||:::"))zip = 0 + zip*10; if(bar.equals(":::||"))zip = 1 + zip*10; if(bar.equals("::|:|"))zip = 2 + zip*10; if(bar.equals("::||:"))zip = 3 + zip*10; if(bar.equals(":|::|"))zip = 4 + zip*10; if(bar.equals(":|:|:"))zip = 5 + zip*10; if(bar.equals(":||::"))zip = 6 + zip*10; if(bar.equals("|:::|"))zip = 7 + zip*10; if(bar.equals("|::|:"))zip = 8 + zip*10; if(bar.equals("|:|::"))zip = 9 + zip*10; } return zip; } private static String calcBarCode(int zip) { String barCode = ""; while (zip > 0) { switch (zip % 10) { case 0: barCode = "||:::" + barCode; break; case 1: barCode = ":::||" + barCode; break; case 2: barCode = "::|:|" + barCode; break; case 3: barCode = "::||:" + barCode; break; case 4: barCode = ":|::|" + barCode; break; case 5: barCode = ":|:|:" + barCode; break; case 6: barCode = ":||::" + barCode; break; case 7: barCode = "|:::|" + barCode; break; case 8: barCode = "|::|:" + barCode; break; case 9: barCode = "|:|::" + barCode; break; } zip = zip / 10; } barCode = "|" + barCode + "|"; return barCode; } /* * Asking the user to enter an zip code and display if it is valid. * If account number is incorrect, the program will ask to continue or not (y). * If valid, program will give barcode. */ private static String calcBarCode(String zipCode1) { return calcBarCode(0); } public static void main(String arg[])throws IOException{ Scanner sc1 = new Scanner(new File("vaildZipCodes.txt")); int i = 0; while(sc1.hasNext()) { vaildZipCodes[i++] = sc1.nextInt(); } // Creating loop for what the user enters boolean newValidator = true; try(Scanner scanner = new Scanner(System.in)){ int zipCode; String barCode; // User inputs while(newValidator) { System.out.print("Enter the zip code: "); String zipCode1 = scanner.nextLine(); if(validator(zipCode1)) { System.out.print("The barcode: " + barcodeMain.calcBarCode(zipCode1)); } else { System.out.println("Not valid zip code number"); newValidator = true; } System.out.println(" Would you like to enter another account number? (y)"); String ans = scanner.nextLine(); if(ans.equals("n") || ans.equals("N")) { newValidator = false; } } System.out.println("** Program Exit **"); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started