Add mm: ss of a column in jtable

0

Good afternoon, I know that the way I explain it is complicated to help me.

I have a jTable that contains a column where times are shown, those times in mm: ss. I need to calculate the average between these times. I made several attempts with different alternatives to get to the goal but I can not even think of a way to perform this calculation.

My difficulty: We have the values inside the colum of the jtable, so these values are Strings.

What I've tried:

  • I tried to create a converter for mm: ss with SimpleDateFormat and store the information in a vector, where after this it would try to add the dates.
  • Result: a bos **, I could not add the way I imagined that I would achieve because however I was using SimpleDateFormat with mm: ss he returned me Thu Jan 01 00:00:10 BRT 1970 .

    Only part of my code:

    for (int i = 0; i < table.getRowCount(); i++) {
            tempo_chegada = table.getValueAt(i, 5).toString();
        }
    

    I can not think of a logic of how I will add being that I only have Strings of a column of a jtable that can exist 1000 lines

    I know it's vague because I do not have a piece of reasoned code, but I do not have the slightest idea of where I can start.

        
    asked by anonymous 18.07.2016 / 20:55

    2 answers

    1

    You started well, just get in the way of handling the data I think ..

    Tentei criar um conversor para mm:ss com SimpleDateFormat e armazenar as 
    informações em um vetor, onde apos isso tentaria somar as datas.
    

    Go back to this point of the idea and make the dates long with Date.getTime () to average.

    Something like this link

        
    18.07.2016 / 21:17
    1

    Something you can do is the following:

    • Retrieve the data as a String.

    Use this code to get the number of minutes and seconds in different variables

    String str = (String) q.getSingleResult();
    
    int posicao = str.indexOf(':');
    if (posicao >= 0) {
      int minutos = str.substring(0, posicao);
      int segundos = str.substring(1, posicao);
    }
    

    From there, multiply the number of minutes by 60, and add the number of seconds to get the total number of seconds for that row. Put this part of the code inside a loop so that you make this calculation for all rows in that column and in the end divide by the number of rows in the table, use the variable "i" to know how many rows have been processed.

    If you have any questions, please comment here.

        
    18.07.2016 / 21:06