array is created and the split method is used, also created an instance of my NameInfo class with the array:
public class NameSearch {
public static void main(String[] args) throws IOException {
NameInfo[] nameList = new NameInfo[151671];
Scanner keyboard = new Scanner(System.in);
String inString = null;
String selectedName;
String anotherName;
int numberOfNames = 0;
int index = 0;
FileReader freader = new FileReader(new File("LastNames2000Census.txt"));
Scanner inputFile = new Scanner(freader);
while (inputFile.hasNext()) {
inString = inputFile.nextLine();
String[] nextString = inString.split(",");
String nextTitle = nextString[0];
int nextRank = Integer.parseInt(nextString[1]);
int nextNumOfOccurrences = Integer.parseInt(nextString[2]);
double nextProp100k = Double.parseDouble(nextString[3]);
double nextCumProp100k = Double.parseDouble(nextString[4]);
nameList[index] = new NameInfo(nextTitle, nextRank, nextNumOfOccurrences, nextProp100k, nextCumProp100k);
index++;
}
array is sorted and searched with insertion and binary generic methods. The error happens in the first line in the print statement:
do {
ArraySort.insertionSort(nameList);
boolean found = false;
System.out.println("Hello, enter a last name.");
selectedName = keyboard.nextLine();
ArraySearch searcher = new ArraySearch(nameList);
if (searcher.binarySearch(nameList, 0, 0, selectedName) == -1)
System.out.println(selectedName + " was not found. Try again.");
else {
System.out.println(
selectedName + " was found at index " + index + "\n ranked: " + nameList[index].getRank()
+ "/n number of occurences: " + nameList[index].getNumOfOccurrences()
+ "\n proportion per 100,000 people: " + nameList[index].getProp100k()
+ "\n cumulative proportion per 100,000 people: " + nameList[index].getCumProp100k());
}
System.out.println("Want to search another name? (Y/N)");
anotherName = keyboard.nextLine();
} while (anotherName.charAt(0) == 'y' || anotherName.charAt(0) == 'Y');
}
}