Help in Study Workshop

1

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]);
    // }
  }


} 
    
asked by Nayrb 12.07.2018 в 04:47
source

1 answer

0

In the puntaje() method you have the variables t , x and a that are never used.

In addition, the condition p.equals(paises[k]) is only fulfilled when there are two equal countries followed because you are reassigning it to p the same value it has, and if it is not fulfilled it passes to puntaje[k] the first value of puntos[] because c is zero.

The same puntaje[] would not need to be ordered because the values are fixed. If what you want is to return the first three places of a country, you could save the country name in a variable outside the cycle and after ordering them go through the arrangement until the país[k] matches three times with that variable.

    
answered by 14.07.2018 в 09:51