Computers and Technology

Zip code and population (generic types) Define a class StatePair with two generic types (Type1 and Type2), a constructor, mutators, accessors, and a printInfo() method. Three ArrayLists have been pre-filled with StatePair data in main(): ArrayList> zipCodeState: Contains ZIP code/state abbreviation pairs ArrayList> abbrevState: Contains state abbreviation/state name pairs ArrayList> statePopulation: Contains state name/population pairs After a ZIP code is read into the program, complete main() to retrieve the correct state abbreviation from the ArrayList zipCodeState. Then use the state abbreviation to retrieve the state name from the ArrayList abbrevState. Lastly, use the state name to retrieve the correct state name/population pair from the ArrayList statePopulation and output the pair. Ex: If the input is 21044 the output is Maryland: 6079602 Code already written:
StatePopulations. java
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.
}
}
}
StatePair. java
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
}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 10:30, Twitches
This first part of the film shows the early history of motion pictures. how accurate do you think the portrayal of the early motion picture industry is? why? is historical accuracy important in films and theatre productions? explain. in the scene where don is going to the party (starting at time code 14: 51), we see a street scene as he first rides with cosmo and then with kathy. what aspects did the filmmaker include to make the scene look and feel like don, cosmo, and kathy are riding in a car on a street? think about elements such as scenery, sound, props, lighting, and so on. a "talkie" picture is shown starting around time code 21: 15. how does the audience in the film react to the "talkie"? what influence do audiences have on film and theatre performances? how do film and theatre actors influence audiences? in the musical scene with cosmo (starting at time code 27: 00), how does the actor use props? what is the result? do you think the use of props effectively fulfilled the artistic vision for this musical number? why or why not?
Answers: 1
image
Computers and Technology, 22.06.2019 10:30, ghazanfarwaheed7967
Auniversity wants to install a client-server network. which feature do you think is important for them as they set up the network? sending email blocking multiple people to use the same file low security low set up cost limited access to files
Answers: 1
image
Computers and Technology, 22.06.2019 18:30, Liantic8738
List the five on-board vehicle subsystems
Answers: 1
image
Computers and Technology, 23.06.2019 12:00, kp2078
What type of slide show is a dynamic and eye-catching way to familiarize potential customers with what your company has to offer? a. ole b. photo album c. brochure d. office clipboard
Answers: 2
Do you know the correct answer?
Zip code and population (generic types) Define a class StatePair with two generic types (Type1 and T...

Questions in other subjects:

Konu
Mathematics, 08.03.2021 21:30
Konu
Mathematics, 08.03.2021 21:30