CymsSoul

Untitled

Apr 6th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1.  
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.util.Collections;
  5. import java.util.List;
  6. import java.util.Random;
  7.  
  8. public class Participant implements Comparable<Participant> {
  9.  
  10. private String name;
  11. private int points;
  12. private int length;
  13. private int[] judgeVotes;
  14. private Random random = new Random();
  15. private List<Integer> allLengths;
  16.  
  17. public Participant(String name) {
  18. this.name = name;
  19. this.points = 0;
  20. this.length = 0;
  21. this.judgeVotes = new int[5];
  22. this.allLengths = new ArrayList<Integer>();
  23. }
  24.  
  25. public int getPoints() {
  26. this.points = this.length + calculateJudgePoints();
  27. return this.points;
  28. }
  29.  
  30. public String getName() {
  31. return this.name;
  32. }
  33.  
  34. public int calculateLength() {
  35. this.length = random.nextInt(120 - 60 + 1) + 60;
  36. setAllLengths(this.length);
  37.  
  38. return this.length;
  39. }
  40.  
  41. public List getAllLengths() {
  42. return this.allLengths;
  43. }
  44.  
  45. public void setAllLengths(int length) {
  46. this.allLengths.add(length);
  47. }
  48.  
  49. public int[] calculateJudgeVotes() {
  50. for (int x = 0; x < judgeVotes.length; x++) {
  51. judgeVotes[x] = random.nextInt(20 - 10 + 1) + 10;
  52. }
  53. return this.judgeVotes;
  54. }
  55.  
  56. private int calculateJudgePoints() {
  57. int pointValue = 0;
  58.  
  59. for (int x = 0; x < judgeVotes.length; x++) {
  60. pointValue += judgeVotes[x];
  61. }
  62. System.out.println("HERE");
  63. pointValue -= findLeastPoints() - findMostPoints();
  64. return pointValue;
  65. }
  66.  
  67. private int findLeastPoints() {
  68. System.out.println("findLeastPoints called:" + Arrays.toString(judgeVotes));
  69.  
  70. int smallestValue = judgeVotes[judgeVotes.length - 1];
  71. for (int x = 0; x < judgeVotes.length; x++) {
  72.  
  73. if (judgeVotes[x] < smallestValue) {
  74. smallestValue = judgeVotes[x];
  75. }
  76. }
  77. return smallestValue;
  78. }
  79.  
  80. private int findMostPoints() {
  81. int largestValue = judgeVotes[judgeVotes.length - 1];
  82. for (int x = 0; x < judgeVotes.length; x++) {
  83. if (judgeVotes[x] > largestValue) {
  84. largestValue = judgeVotes[x];
  85. }
  86. }
  87. return largestValue;
  88. }
  89.  
  90. @Override
  91. public int compareTo(Participant p) {
  92. if (this.getPoints() == p.getPoints()) {
  93. return 0;
  94. } else if (this.getPoints() > p.getPoints()) {
  95. return 1;
  96. } else {
  97. return -1;
  98. }
  99. }
  100.  
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment