Question: please help with this code. please only do the the TODO section as thtas all it needs. I gave a description of the todo in

please help with this code. please only do the the TODO section as thtas all it needs. I gave a description of the todo in this assignment.

Code to write:

StatePair.java

// TODO: Define a constructor, mutators, and accessors

// for StatePair

Constructor needs to take two objects and set the values of the properties. Note: pay attention to what these properties are defined as

Code getKey and setKey which will be used for both zip code and state abbreviation. Remember these are generic types

Code getValue and setValue which will be used for both zip cdoe and state

// TODO: Define printInfo() method

Display the information (Hint: use key and value in your code)

StatePopulations.java

// TODO: Using ZIP code, find state abbreviation

For loop reading through zipCodeState array

If myZipCode value is a key in the array

Assign the corresponding value to myStateAbbrev

// TODO: Using state abbreviation, find state

For loop reading through abbrevState array

If myStateAbbrev is a key in the array

Assign the corresponding value to myState

// TODO: Using state, find population. Print information.

For loop reading through statePopulation array

If myState is a key in the array

Call the printInfo method of statePopulation

NOTE: It is extremely important to understand how StatePair and StatePopluations tie together. In the code you write for StatePopulations you will be using the getKey and getValue methods

Here is the existing code, please plug in the rest.

import java.util.Scanner; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList;

public class StatePopulations {

public static ArrayList> fillArray1(ArrayList> statePairs, Scanner inFS) { StatePair pair; int intValue; String stringValue;

while (inFS.hasNextLine()) { intValue = inFS.nextInt(); stringValue = inFS.next(); pair = new StatePair (intValue, stringValue); statePairs.add(pair); } return statePairs; } public static ArrayList> fillArray2(ArrayList> statePairs, Scanner inFS) { StatePair pair; String stringValue1; String stringValue2;

while (inFS.hasNextLine()) { stringValue1 = inFS.next(); inFS.nextLine(); stringValue2 = inFS.nextLine(); pair = new StatePair (stringValue1, stringValue2); statePairs.add(pair); } return statePairs; } public static ArrayList> fillArray3(ArrayList> statePairs, Scanner inFS) { StatePair pair; String stringValue; int intValue;

while (inFS.hasNextLine()) { stringValue = inFS.nextLine(); intValue = inFS.nextInt(); inFS.nextLine(); pair = new StatePair (stringValue, intValue); statePairs.add(pair); } return statePairs; } public static void main(String[] args) throws IOException { Scanner scnr = new Scanner(System.in); FileInputStream fileByteStream = null; // File input stream Scanner inFS = null; // Scanner object int myZipCode; int i; // ZIP code - state abbrev. pairs ArrayList> zipCodeState = new ArrayList>(); // state abbrev. - state name pairs ArrayList> abbrevState = new ArrayList>(); // state name - population pairs ArrayList> statePopulation = new ArrayList>(); // Fill the three ArrayLists // Try to open zip_code_state.txt file fileByteStream = new FileInputStream("zip_code_state.txt"); inFS = new Scanner(fileByteStream); zipCodeState = fillArray1(zipCodeState, inFS); fileByteStream.close(); // close() may throw IOException if fails // Try to open abbreviation_state.txt file fileByteStream = new FileInputStream("abbreviation_state.txt"); inFS = new Scanner(fileByteStream); abbrevState = fillArray2(abbrevState, inFS); fileByteStream.close(); // close() may throw IOException if fails // Try to open state_population.txt file fileByteStream = new FileInputStream("state_population.txt"); inFS = new Scanner(fileByteStream); statePopulation = fillArray3(statePopulation, inFS); fileByteStream.close(); // close() may throw IOException if fails // Read in ZIP code from user myZipCode = scnr.nextInt(); for (i = 0; i < zipCodeState.size(); ++i) { // TODO: Using ZIP code, find state abbreviation } for (i = 0; i < abbrevState.size(); ++i) { // TODO: Using state abbreviation, find state name } for (i = 0; i < statePopulation.size(); ++i) { // TODO: Using state name, find population. Print pair info. } } }

public class StatePair , Type2 extends Comparable> { private Type1 value1; private Type2 value2; // TODO: Define a constructor, mutators, and accessors // for StatePair // TODO: Define printInfo() method }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!