Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.ArrayList;
  3. import java.util.Random;
  4.  
  5. public class UserInterface {
  6.  
  7. private Random rand;
  8. private Scanner read;
  9. private Participants participant;
  10. private ArrayList<Participants> list;
  11.  
  12. public UserInterface(Scanner read) {
  13. this.read = read;
  14. this.rand = new Random();
  15. list = new ArrayList<Participants>();
  16. }
  17.  
  18. public void start() {
  19. sText();
  20. addParticipants();
  21. play();
  22. results();
  23. }
  24.  
  25. public void sText() {
  26. System.out.println("Kumpula ski jumping week");
  27. System.out.println("");
  28. System.out.println("Write the name of the participants one at a time; "
  29. + "an empty string brings you to the jumping phase.");
  30. }
  31.  
  32. public void addParticipants() {
  33. while(true){
  34. System.out.print("Participant name: ");
  35. String name = read.nextLine();
  36. if (name.isEmpty()){
  37. break;
  38. } else {
  39. participant = new Participants(name);
  40. list.add(participant);
  41. }
  42. }
  43. System.out.println("");
  44. }
  45.  
  46. public void play() {
  47. System.out.println("The tournament begins!");
  48. System.out.println("");
  49. int count = 0;
  50.  
  51. while (true) {
  52. System.out.print("Write 'jump' to jump; otherwise you quit: ");
  53. String input = read.nextLine();
  54. if (!input.equals("jump")) {
  55. break;
  56. } else {
  57. count++;
  58. System.out.println("Round " + count + "\n");
  59. jumpOrder();
  60.  
  61. for (Participants people : list){
  62. people.jump();
  63. people.judge();
  64. }
  65. System.out.println("\n" + "Results of round " + count);
  66. roundResults();
  67. for (Participants people : list) {
  68. people.judgeSort();
  69. }
  70. }
  71. }
  72. }
  73.  
  74. public void jumpOrder() {
  75. System.out.println("Jumping order: ");
  76. int i = 0;
  77.  
  78. for (Participants people : list) {
  79. i++;
  80. System.out.println(" " + i + ". " + people.getName() + " (" + people.getTotal() + " points)");
  81. }
  82. }
  83.  
  84. public void roundResults() {
  85. for (Participants people : list) {
  86. System.out.println(" " + people.getName() );
  87. System.out.println(" length: " + people.getLength() );
  88. System.out.println(" judge votes: " + people.listJudges() );
  89. }
  90. System.out.println("");
  91. }
  92.  
  93. public void results() {
  94. System.out.println("Thanks!\n");
  95. System.out.println("Tournament results:");
  96. System.out.println("Position Name");
  97. int count = 0;
  98. for (Participants name : list) {
  99. count++;
  100. System.out.println(count + " " + name.getName() + " (" + name.getTotal() + " points)");
  101. System.out.println(" jump lengths:" + name.listJumps() );
  102. }
  103. }
  104. }
  105. -------------------------------------------------------
  106. import java.util.ArrayList;
  107. import java.util.Collections;
  108.  
  109. public class Participants implements Comparable<Participants> {
  110.  
  111. private String name;
  112. private ArrayList<Integer> jumps;
  113. private ArrayList<Integer> judges;
  114. private int jTotal;
  115. private int length;
  116.  
  117. public Participants(String name) {
  118. this.name = name;
  119. this.jTotal = 0;
  120. jumps = new ArrayList<Integer>();
  121. }
  122.  
  123. public void jump() {
  124. length = (int) ((Math.random() * ((120 - 60) + 1)) + 60);
  125. jumps.add(length);
  126. }
  127.  
  128. public void judge() {
  129. judges = new ArrayList<Integer>();
  130. if (judges.size() > 0) {
  131. judges.clear();
  132. }
  133.  
  134. for (int i = 0; i < 5; i++){
  135. int temp = (int) ((Math.random() * ((20-10) + 1)) + 10);
  136. judges.add(temp);
  137. }
  138. }
  139.  
  140. public void judgeSort() {
  141. int i = 1;
  142.  
  143. Collections.sort(judges);
  144. while (i < 4){
  145. int points = judges.get(i);
  146. jTotal += points;
  147. i++;
  148. }
  149. }
  150.  
  151. public ArrayList<Integer> listJudges() {
  152. return judges;
  153. }
  154.  
  155. public int getLength() {
  156. return length;
  157. }
  158.  
  159. public String getName() {
  160. return this.name;
  161. }
  162.  
  163. public ArrayList<Integer> listJumps() {
  164. return jumps;
  165. }
  166.  
  167. public int getjTotal() {
  168. return jTotal;
  169. }
  170.  
  171. public int getTotal() {
  172. int temp = 0;
  173. for (Integer jump : jumps) {
  174. temp += jump;
  175. }
  176. return temp + jTotal;
  177. }
  178.  
  179. @Override
  180. public int compareTo(Participants people) {
  181. return this.jTotal - people.getjTotal();
  182. }
  183.  
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement