public static void main(String[] args) {

		/** A Utility class. */
		class ZipStatePair {

			String zip;

			String state;


			ZipStatePair(String zip, String state) {
				this.state = state;
				this.zip = zip;
			}
		}


		//create a list of mappings from zipcode to state
		LinkedList<ZipStatePair> pairs = new LinkedList<ZipStatePair>();

		//read the ZIP to STATE map
		try {
			BufferedReader br = new BufferedReader(new FileReader("ZIP_CODES.txt"));

			StringTokenizer st;
			String line;

			line = br.readLine();  //read 1st line

			//a line consists of the following tokens
			//ZIPCODE STATE
			while (line != null) {
				st = new StringTokenizer(line);

				String trueZip = st.nextToken();
				String state = st.nextToken();

				pairs.addLast(new ZipStatePair(trueZip, state));

				line = br.readLine();
			}
		} catch (Exception ex) {
			ex.printStackTrace();
			System.exit(0);
		}


		//get the list of zipcodes
		LinkedList<ZipcodeEntry> zipcodes = readInputFile();

		//give each zipcode a state
		ZipStatePair[] array = pairs.toArray(new ZipStatePair[0]);
		for (ZipcodeEntry zip : zipcodes) {
			for (int i = 0; i < array.length; i++) {
				if (array[i].zip.equals(zip.realWorldZip)) {
					zip.state = array[i].state;
				}
			}
		}


		//write out the results
		StringBuffer output = new StringBuffer();
		for (ZipcodeEntry zip : zipcodes) {
			output.append(
					zip.realWorldZip + "\t" +
					zip.population + "\t" +
					zip.y + "\t" +
					zip.x + "\t" +
					zip.state + "\n");
		}

		try {
			FileUtility.writeToNewFile("withZipData.txt", output.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}

	}