CymsSoul

Untitled

Apr 6th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 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.Scanner;
  7.  
  8. public class Tournament {
  9.  
  10. private Scanner reader;
  11. private List<Participant> participantList;
  12. private int rounds;
  13.  
  14. public Tournament(Scanner reader) {
  15. this.reader = reader;
  16. this.participantList = new ArrayList<Participant>();
  17. this.rounds = 0;
  18. }
  19.  
  20. public void start() {
  21. introduction();
  22. String participantName = null;
  23.  
  24. while (true) {
  25. System.out.print(" Participant name: ");
  26. participantName = reader.nextLine();
  27. if (participantName.isEmpty()) {
  28. break;
  29. }
  30. participantList.add(new Participant(participantName));
  31. }
  32. System.out.println();
  33. beginTournament();
  34. }
  35.  
  36. public void introduction() {
  37. System.out.println("Kumpula ski jumping week");
  38. System.out.println();
  39. System.out.println("Write the names of the participants one at a time; an empty string brings you to the jumping phase.");
  40. }
  41.  
  42. private void beginTournament() {
  43. System.out.println("The tournament begins!");
  44. System.out.println();
  45. while (true) {
  46. System.out.print("Write \"jump\" to jump; otherwise you quit: ");
  47. String toJump = reader.nextLine();
  48. System.out.println();
  49. if (!toJump.equalsIgnoreCase("jump")) {
  50. System.out.println("Thanks!");
  51. System.out.println();
  52. endResults();
  53. break;
  54. }
  55. this.rounds++;
  56. startJumping();
  57. }
  58.  
  59. }
  60.  
  61. private void startJumping() {
  62. System.out.println("Round " + this.rounds);
  63. System.out.println();
  64. System.out.println("Jumping order:");
  65. int count = 1;
  66. sortByLeastPointsFirst();
  67.  
  68. for (Participant p : this.participantList) {
  69. System.out.println(" " + count + ". " + p.getName() + " (" + p.getPoints() + " points)");
  70. count++;
  71. }
  72. results();
  73. }
  74.  
  75. public void sortByLeastPointsFirst() {
  76. Collections.sort(participantList);
  77. }
  78.  
  79. private void results() {
  80. System.out.println("Results of round " + rounds);
  81. for (Participant p : this.participantList) {
  82. System.out.println(" " + p.getName());
  83. System.out.println(" length: " + p.calculateLength());
  84. System.out.println(" judge votes: " + Arrays.toString(p.calculateJudgeVotes()));
  85. }
  86. }
  87.  
  88. private void endResults() {
  89. System.out.println("Tournament results:");
  90. System.out.print("Position ");
  91. System.out.println("Name");
  92.  
  93. int count = 1;
  94. for (Participant p : this.participantList) {
  95. System.out.println(count + " " + p.getName() + " (" + p.getPoints() + " points)");
  96. System.out.print(" jump lengths: ");
  97. getLengthInfo(p);
  98. count++;
  99. System.out.println();
  100. }
  101. }
  102.  
  103. private void getLengthInfo(Participant p) {
  104. for (int i = 0; i < p.getAllLengths().size(); i++) {
  105. List<Integer> subList = p.getAllLengths().subList(p.getAllLengths().size() - 1, p.getAllLengths().size());
  106. int[] convertSubList = new int[subList.size()];
  107. for (int x = 0; x < convertSubList.length; x++) {
  108. convertSubList[x] = subList.get(x).intValue();
  109. }
  110. if (p.getAllLengths().get(i).equals(convertSubList[0])) {
  111. System.out.print(" " + p.getAllLengths().get(i).toString() + " m");
  112. } else {
  113. System.out.print(" " + p.getAllLengths().get(i).toString() + " m,");
  114. }
  115.  
  116. }
  117. }
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment