I have a problem with my code I have to do this work, and I can not calculate the total values by reading an external file, with these characteristics in Java.
I have this code worked, that calculates the values of the score of the competitors but all in a one-dimensional array, but in the total calculation of each one, there I am half dizzy.
ucn is the library of the University that modifies some sentences of java.
Greetings
import java.util.Arrays;
import ucn.*;
public class TallerTP {
String Paises[] = new String[8];
String Pilotos[] = new String[8];
double Horas[] = new double[8];
int Puntaje[] = new int[8];
String PilotosPuntaje[][] = new String[8][2];
public static void main(String[] args) {
TallerTP pv = new TallerTP();
pv.cargar();
//StdOut.println("Ordenados Paises");
//pv.ordenarPaises();
//pv.imprimir();
StdOut.println("Ordenados Horas");
pv.ordenarHoras();
pv.puntaje();
pv.imprimir();
}
public void cargar(){
In entrada=new In ("wrc.txt");
while(!entrada.isEmpty()){
for(int i=0; i<8; i++){
Paises[i] = entrada.readString();
Pilotos[i] = entrada.readString();
Horas[i] = entrada.readDouble();
}
}
entrada.close();
}
// public void ordenarPaises(){
// for(int k=0; k<Paises.length; k++){
// for(int f=0; f<Paises.length-1-k; f++){
// if (Paises[f].compareTo(Paises[f+1])>0){
// String auxpais;
// auxpais = Paises[f];
// Paises[f] = Paises[f+1];
// Paises[f+1] = auxpais;
// String auxpiloto;
// auxpiloto = Pilotos[f];
// Pilotos[f] = Pilotos[f+1];
// Pilotos[f+1] = auxpiloto;
// double auxhoras;
// auxhoras = Horas[f];
// Horas[f] = Horas[f+1];
// Horas[f+1] = auxhoras;
// }
// }
// }
//
// }
public void ordenarHoras(){
for(int k=0; k<Horas.length; k++){
for(int f=0; f<Horas.length-1-k; f++){
if (Horas[f]>Horas[f+1]){
double auxhoras;
auxhoras = Horas[f];
Horas[f] = Horas[f+1];
Horas[f+1] = auxhoras;
String auxpais;
auxpais = Paises[f];
Paises[f] = Paises[f+1];
Paises[f+1] = auxpais;
String auxpiloto;
auxpiloto = Pilotos[f];
Pilotos[f] = Pilotos[f+1];
Pilotos[f+1] = auxpiloto;
}
}
}
}
public void puntaje(){
String p = Paises[0];
String t = Pilotos[0];
int x = 0;
int a = 0;
int c = 0;
int Puntos[] = {25,18,15,12,10,8,6,4,2,1};
for (int k=0; k<Puntaje.length; k++) {
if (c < 10 && p.equals(Paises[k])) {
p = Paises[k];
Puntaje[k] = Puntos[c];
c = c + 1;
}else{
c = 0;
Puntaje[k] = Puntos[c];
p = Paises[k];
c = c + 1;
}
}
}
public void imprimir() {
for(int f=0; f<Paises.length; f++){
StdOut.println(Paises[f] + " - "+ Pilotos[f] +" - "+ Horas[f] +" - "+Puntaje[f]);
}
//for(int d=0; d<PilotosPuntaje.length; d++){
//StdOut.println(PilotosPuntaje[d][0] +" - "+ PilotosPuntaje[d][1]);
// }
}
}