Pessol to lendo um arquivo texto com o resultado de um concurso. To separando os nomes através da "/" e separando tb a nota de cada um, porem ao ordenar as notas nao sei como puxar os nomes das pessoas melhores classificadas.
Alguem tem sugestao pra melhorar esse código? Vou mandar tb o arquivo texto q tou usando
import java.io.*;
/**
*
* @author nilson
*/
public class NovoClass {
public String retornaString(String fileName) throws IOException {
BufferedReader in = new BufferedReader(new FileReader(fileName));
String line;
StringBuffer buffer = new StringBuffer();
while( (line = in.readLine()) != null ){
buffer.append(line + "\n");
}
in.close();
return buffer.toString();
}
public static void main(String args[]) {
String teste="", output = "";
String vet[];
double not[];
Ler t = new Ler();
try {
teste = t.retornaString("C:\tre_notas.txt");
} catch (IOException ex) {
ex.printStackTrace();
}
int count = 0, i = 0;
vet = new String[teste.length()+1];
while (count < teste.length()){
if (teste.charAt(count)!='/')
vet[i]+=teste.charAt( count );
else
i++;
count++;
}
int indice = i - 1;
not = new double[teste.length()+1];
for (i=0;i<indice;i++)
{
String aux="",pal;
pal=vet[i].substring(vet[i].length()-5,vet[i].length()-1);
aux+=pal.charAt(0)+"."+pal.charAt(2)+pal.charAt(3);
not[i]=Double.parseDouble(aux);
}
for (i=0;i<indice;i++)
{
int k = i;
for (int j = i + 1; j < indice; j++)
if ( not [ j ] < not [ k ] )
k = j;
swap( not,k, i );
}
int j=1;
for (i=indice-1;i>=0;i--)
{
System.out.println(j+":"+" "+Double.toString(not[i]));
j++;
}
}
public static void swap ( double [ ] v, int j, int aposJ )
{
double aux = 0.0;
aux = v [ j ];
v [ j ] = v [ aposJ ];
v [ aposJ ] = aux;
}
}