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.Scanner;
- public class Tournament {
- private Scanner reader;
- private List<Participant> participantList;
- private int rounds;
- public Tournament(Scanner reader) {
- this.reader = reader;
- this.participantList = new ArrayList<Participant>();
- this.rounds = 0;
- }
- public void start() {
- introduction();
- String participantName = null;
- while (true) {
- System.out.print(" Participant name: ");
- participantName = reader.nextLine();
- if (participantName.isEmpty()) {
- break;
- }
- participantList.add(new Participant(participantName));
- }
- System.out.println();
- beginTournament();
- }
- public void introduction() {
- System.out.println("Kumpula ski jumping week");
- System.out.println();
- System.out.println("Write the names of the participants one at a time; an empty string brings you to the jumping phase.");
- }
- private void beginTournament() {
- System.out.println("The tournament begins!");
- System.out.println();
- while (true) {
- System.out.print("Write \"jump\" to jump; otherwise you quit: ");
- String toJump = reader.nextLine();
- System.out.println();
- if (!toJump.equalsIgnoreCase("jump")) {
- System.out.println("Thanks!");
- System.out.println();
- endResults();
- break;
- }
- this.rounds++;
- startJumping();
- }
- }
- private void startJumping() {
- System.out.println("Round " + this.rounds);
- System.out.println();
- System.out.println("Jumping order:");
- int count = 1;
- sortByLeastPointsFirst();
- for (Participant p : this.participantList) {
- System.out.println(" " + count + ". " + p.getName() + " (" + p.getPoints() + " points)");
- count++;
- }
- results();
- }
- public void sortByLeastPointsFirst() {
- Collections.sort(participantList);
- }
- private void results() {
- System.out.println("Results of round " + rounds);
- for (Participant p : this.participantList) {
- System.out.println(" " + p.getName());
- System.out.println(" length: " + p.calculateLength());
- System.out.println(" judge votes: " + Arrays.toString(p.calculateJudgeVotes()));
- }
- }
- private void endResults() {
- System.out.println("Tournament results:");
- System.out.print("Position ");
- System.out.println("Name");
- int count = 1;
- for (Participant p : this.participantList) {
- System.out.println(count + " " + p.getName() + " (" + p.getPoints() + " points)");
- System.out.print(" jump lengths: ");
- getLengthInfo(p);
- count++;
- System.out.println();
- }
- }
- private void getLengthInfo(Participant p) {
- for (int i = 0; i < p.getAllLengths().size(); i++) {
- List<Integer> subList = p.getAllLengths().subList(p.getAllLengths().size() - 1, p.getAllLengths().size());
- int[] convertSubList = new int[subList.size()];
- for (int x = 0; x < convertSubList.length; x++) {
- convertSubList[x] = subList.get(x).intValue();
- }
- if (p.getAllLengths().get(i).equals(convertSubList[0])) {
- System.out.print(" " + p.getAllLengths().get(i).toString() + " m");
- } else {
- System.out.print(" " + p.getAllLengths().get(i).toString() + " m,");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment