Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.List;
- import java.util.Random;
- public class Participant implements Comparable<Participant> {
- private String name;
- private int points;
- private int length;
- private int[] judgeVotes;
- private Random random = new Random();
- private List<Integer> allLengths;
- public Participant(String name) {
- this.name = name;
- this.points = 0;
- this.length = 0;
- this.judgeVotes = new int[5];
- this.allLengths = new ArrayList<Integer>();
- }
- public int getPoints() {
- this.points = this.length + calculateJudgePoints();
- return this.points;
- }
- public String getName() {
- return this.name;
- }
- public int calculateLength() {
- this.length = random.nextInt(120 - 60 + 1) + 60;
- setAllLengths(this.length);
- return this.length;
- }
- public List getAllLengths() {
- return this.allLengths;
- }
- public void setAllLengths(int length) {
- this.allLengths.add(length);
- }
- public int[] calculateJudgeVotes() {
- for (int x = 0; x < judgeVotes.length; x++) {
- judgeVotes[x] = random.nextInt(20 - 10 + 1) + 10;
- }
- return this.judgeVotes;
- }
- private int calculateJudgePoints() {
- int pointValue = 0;
- for (int x = 0; x < judgeVotes.length; x++) {
- pointValue += judgeVotes[x];
- }
- System.out.println("HERE");
- pointValue -= findLeastPoints() - findMostPoints();
- return pointValue;
- }
- private int findLeastPoints() {
- int smallestValue = judgeVotes[judgeVotes.length - 1];
- for (int x = 0; x < judgeVotes.length; x++) {
- if (judgeVotes[x] < smallestValue) {
- smallestValue = judgeVotes[x];
- }
- }
- return smallestValue;
- }
- private int findMostPoints() {
- int largestValue = judgeVotes[judgeVotes.length - 1];
- for (int x = 0; x < judgeVotes.length; x++) {
- if (judgeVotes[x] > largestValue) {
- largestValue = judgeVotes[x];
- }
- }
- return largestValue;
- }
- @Override
- public int compareTo(Participant p) {
- if (this.getPoints() == p.getPoints()) {
- return 0;
- } else if (this.getPoints() > p.getPoints()) {
- return 1;
- } else {
- return -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment