Advertisement
PhilHole

Untitled

Oct 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement