doubt with algorithm

3

I have to develop an algorithm that calculates the average speed of the orders that were delivered. This is calculated based on the production times and the number of units that each order has; but these are taken into account according to a date history delivered by the user from which they begin to consider the orders for the calculation.

It turns out that all the data come from an Excel file, so they are read in double , but when running the program I get an error "NaN" (not a number), I do not understand what the problem is. Attached part of the code

Class method requested for speed calculation:

public double CalcularVelocidadL1(Date fechaHist){
    llenarLista();//metodo que me llena la lista en la que voy a trabajar
    double suma=0;
    int cont=0;
    NodoListaL1 aux= headL1;
    while(aux.getNext()!=null){
        if(aux.getNext().getDato().getFec_ped().after(fechaHist)||  aux.getNext().getDato().getFec_ped().equals(fechaHist)){
            double num=aux.getNext().getDato().getUni_lot();
            double den=aux.getNext().getDato().getTmp_proc();
            double div=num/den;
            suma=suma+div;
            cont++;
        }
    }
    aux=aux.getNext();
    double vel=(suma/cont);
    return vel;
}

Main method where the date is requested:

public static void main(String[]args)throws IOException, ParseException{
    BufferedReader lector=new BufferedReader(new InputStreamReader(System.in));
    LeerExcel excel=new LeerExcel();
    excel.Leer();

    System.out.println("ingrese fecha");
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    String f=lector.readLine();
    Date fecha=sdf.parse(f);

    ArraylistP v =new ArraylistP();
    double d=v.CalcularVelocidadL1(fecha);
    System.out.println(d);
}
    
asked by sebastian 09.10.2016 в 06:30
source

1 answer

1

You may have an XY problem. That is, your symptom is a NAN and you ask about it, but your problem is different. Concisely the getNext()

In your question you do not put the class NodoListaL1 so we do not know what it does. This makes it difficult to answer you. When asking a question, it is best to put a minimum, complete and verifiable example . That in this case should include the class NodeListL1 and possibly LeerExcel . Remove everything you can remove, so it's minimal. But the program must be able to run and show the error. It also includes a link to an Excel test.

Still missing elements to answer you it is easy to imagine that the function getNext() returns an element and advances an internal counter so that successive calls return later elements. But presumably you want to treat the same element in each iteration of the loop. In this case you want a loop such that:

NodoListaL1 aux= headL1;
for(;;)
{
  AlgunTipo elemento;
  elemento = aux.getNext();
  if (elemento==null)
    break;
  if(elemento.getDato().getFec_ped().after(fechaHist)||  elemento.getDato().getFec_ped().equals(fechaHist)){
      double num=elemento.getDato().getUni_lot();
      double den=elemento.getDato().getTmp_proc();
      double div=num/den;
      suma=suma+div;
      cont++;
  }
}

Although it is also possible that you have a XXY problem. That is, you have 2 problems, the NAN and the getNext() . With a question with the elements indicated above, it would be possible to discern this.

    
answered by 16.06.2017 в 09:11