daily pastebin goal
28%
SHARE
TWEET

Untitled

PhilHole Oct 17th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ee.ttu.algoritmid.scoreboard;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.Comparator;
  6. import java.util.List;
  7.  
  8. public class ScoreBoard {
  9.     /**
  10.      * Adds a participant's time to the checkpoint scoreboard
  11.      *
  12.      */
  13.  
  14.     ArrayList<Participant> participants;
  15.  
  16.     public void add(Participant participant) {
  17.         participants.add(participant);
  18.     }
  19.  
  20.     /**
  21.      * Returns top n number of participants in the checkpoint to be displayed on the scoreboard
  22.      * This method will be queried by the tests every time a new participant is added
  23.      */
  24.     public List<Participant> get(int n) {
  25.  
  26.         participants.sort(Comparator.comparing(Participant::getTime));
  27.  
  28.         ArrayList<Participant> topN = new ArrayList<>();
  29.  
  30.         for (int i = 0; i < n; i++) {
  31.             topN.add(participants.get(i));
  32.         }
  33.         return topN;
  34.     }
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top