Advertisement
LucasSousa

OverallAverage (statistic provider)

Oct 21st, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. package br.estatisticas;
  2.  
  3. import br.modelos.Solve;
  4. import java.util.ArrayList;
  5. import java.util.Collections;
  6.  
  7. /**
  8.  * Criado por Lucas Sousa em 21/10/2015.
  9.  */
  10. public class OverallAverage {
  11.  
  12.     private ArrayList<Solve> solves;
  13.  
  14.     public OverallAverage(ArrayList<Solve> solves){
  15.         this.solves = solves;
  16.     }
  17.  
  18.     public long getOverallAverage(){
  19.         if (solves != null){
  20.             if (solves.size() >= 3){
  21.                 ArrayList<Long> longTimes = new ArrayList<>();
  22.  
  23.                 for (Solve s : solves){
  24.                     longTimes.add(s.getTime());
  25.                 }
  26.                 longTimes.remove(Collections.max(longTimes));
  27.                 longTimes.remove(Collections.min(longTimes));
  28.  
  29.                 long somatorio = 0;
  30.                 for (long x : longTimes){
  31.                     somatorio += x;
  32.                 }
  33.                 return (somatorio / longTimes.size());
  34.             }
  35.         }
  36.         return 0;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement