Okay so here is my problem, I am trying to pass a string of lets say "Bulbasaur" into getSpecific(string name) in order to get the returned array of pokemonInfo;
getSpecific(int i) does work and returns
{001,Bulbasaur,Grass,Poison,1,2,0,-1}
every value in that array is a String(just fyi)
so I want to be able to search through my IO file that i have for a specific pokemon name and return the array corresponding to it's array position.
I don't know if this will be as confusing to you as it is to me atm.
Thanks for your time reading this.
Code
import java.util.Scanner;
import java.io.*;
/**
* Write a description of class loadPokemon here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class loadPokemon{
private String filename = "poke.txt";
private String pokemonData;
public String[] pokemonInfo;
public loadPokemon()throws IOException{
File file = new File(filename);
Scanner inputFile = new Scanner(file);
while(inputFile.hasNext()){
pokemonData = inputFile.nextLine();
pokemonInfo = pokemonData.split("~");
}
}
public String[] getSpecific(int i){
return pokemonInfo[i].split(",");
}
public String[] getSpecific(String name)throws IOException{
int index, element;
boolean found;
index =0;
element = -1;
found=false;
loadPokemon lp = new loadPokemon();
while(!false && index < pokemonInfo.length){
String[] data = lp.getSpecific(index);
if(name.equals(data[index]) && index < 8){
found = true;
element = index;
}
index++;
}
if(element != -1){
index = (element - 1);
return pokemonInfo[index].split(",");
}else{
return null;
}
}
}