Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ee.ttu.algoritmid.scoreboard;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Comparator;
- import java.util.List;
- public class ScoreBoard {
- /**
- * Adds a participant's time to the checkpoint scoreboard
- *
- */
- ArrayList<Participant> participants;
- public void add(Participant participant) {
- participants.add(participant);
- }
- /**
- * Returns top n number of participants in the checkpoint to be displayed on the scoreboard
- * This method will be queried by the tests every time a new participant is added
- */
- public List<Participant> get(int n) {
- participants.sort(Comparator.comparing(Participant::getTime));
- ArrayList<Participant> topN = new ArrayList<>();
- for (int i = 0; i < n; i++) {
- topN.add(participants.get(i));
- }
- return topN;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement