I'm doing a Formula 1 Racing program, my program reads various racing files, and creates the test objects. I need to deploy in this program a class that has an array to store only the Pilots that have points above 0, and if the pilot is already in the array, their score must be updated, but the objects are not being created in the array: / p>
Part of the main class:
public class Controle {
public static void main(String[] args) {
Temporada2013 temporada = new Temporada2013();
File arquivos[];
File diretorio = new File("/Users/leonardobruksch/NetBeansProjects/Corridas");
arquivos = diretorio.listFiles();
for(int a=0;a<arquivos.length;a++){
Provas prova = new Provas();
try {
FileReader fr = new FileReader(arquivos[a]);
BufferedReader in = new BufferedReader(fr);
String line = in.readLine();
line = in.readLine();
while (line != null) {
String result[] = line.split(";");
int x = Integer.parseInt(result[6]);
prova.inserePiloto(result[0], result[1], result[2], result[3], result[4], result[5], x);
if(x > 0)
temporada.inserePilotosPontuados(result[1], result[2], x);
line = in.readLine();
}
Part of the class Season2013 that performs the insertion:
public class Temporada2013 {
Piloto[] pontuados = new Piloto[30];
public void inserePilotosPontuados(String driver, String team, int points) {
for(int i=0;i<getLast();i++){
if(pontuados[i].getDriver().equalsIgnoreCase(driver)){
pontuados[i].setPoints(pontuados[i].getPoints()+points);
return;
}
}
pontuados[getLast()] = new Piloto(driver, team, points);
}
private int getLast(){
int last = 0;
for(int i=0;i<pontuados.length;i++){
if(pontuados[i] == null)
last = i;
return last;
}
return last;
}
What is happening is that the above method, after being executed and displayed, is creating only one object in the array, instead of creating several.