CymsSoul

Untitled

Apr 6th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 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.  
  69. int smallestValue = judgeVotes[judgeVotes.length - 1];
  70. for (int x = 0; x < judgeVotes.length; x++) {
  71.  
  72. if (judgeVotes[x] < smallestValue) {
  73. smallestValue = judgeVotes[x];
  74. }
  75. }
  76. return smallestValue;
  77. }
  78.  
  79. private int findMostPoints() {
  80. int largestValue = judgeVotes[judgeVotes.length - 1];
  81. for (int x = 0; x < judgeVotes.length; x++) {
  82. if (judgeVotes[x] > largestValue) {
  83. largestValue = judgeVotes[x];
  84. }
  85. }
  86. return largestValue;
  87. }
  88.  
  89. @Override
  90. public int compareTo(Participant p) {
  91. if (this.getPoints() == p.getPoints()) {
  92. return 0;
  93. } else if (this.getPoints() > p.getPoints()) {
  94. return 1;
  95. } else {
  96. return -1;
  97. }
  98. }
  99.  
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment