Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.ArrayList;
- import java.util.Random;
- public class UserInterface {
- private Random rand;
- private Scanner read;
- private Participants participant;
- private ArrayList<Participants> list;
- public UserInterface(Scanner read) {
- this.read = read;
- this.rand = new Random();
- list = new ArrayList<Participants>();
- }
- public void start() {
- sText();
- addParticipants();
- play();
- results();
- }
- public void sText() {
- System.out.println("Kumpula ski jumping week");
- System.out.println("");
- System.out.println("Write the name of the participants one at a time; "
- + "an empty string brings you to the jumping phase.");
- }
- public void addParticipants() {
- while(true){
- System.out.print("Participant name: ");
- String name = read.nextLine();
- if (name.isEmpty()){
- break;
- } else {
- participant = new Participants(name);
- list.add(participant);
- }
- }
- System.out.println("");
- }
- public void play() {
- System.out.println("The tournament begins!");
- System.out.println("");
- int count = 0;
- while (true) {
- System.out.print("Write 'jump' to jump; otherwise you quit: ");
- String input = read.nextLine();
- if (!input.equals("jump")) {
- break;
- } else {
- count++;
- System.out.println("Round " + count + "\n");
- jumpOrder();
- for (Participants people : list){
- people.jump();
- people.judge();
- }
- System.out.println("\n" + "Results of round " + count);
- roundResults();
- for (Participants people : list) {
- people.judgeSort();
- }
- }
- }
- }
- public void jumpOrder() {
- System.out.println("Jumping order: ");
- int i = 0;
- for (Participants people : list) {
- i++;
- System.out.println(" " + i + ". " + people.getName() + " (" + people.getTotal() + " points)");
- }
- }
- public void roundResults() {
- for (Participants people : list) {
- System.out.println(" " + people.getName() );
- System.out.println(" length: " + people.getLength() );
- System.out.println(" judge votes: " + people.listJudges() );
- }
- System.out.println("");
- }
- public void results() {
- System.out.println("Thanks!\n");
- System.out.println("Tournament results:");
- System.out.println("Position Name");
- int count = 0;
- for (Participants name : list) {
- count++;
- System.out.println(count + " " + name.getName() + " (" + name.getTotal() + " points)");
- System.out.println(" jump lengths:" + name.listJumps() );
- }
- }
- }
- -------------------------------------------------------
- import java.util.ArrayList;
- import java.util.Collections;
- public class Participants implements Comparable<Participants> {
- private String name;
- private ArrayList<Integer> jumps;
- private ArrayList<Integer> judges;
- private int jTotal;
- private int length;
- public Participants(String name) {
- this.name = name;
- this.jTotal = 0;
- jumps = new ArrayList<Integer>();
- }
- public void jump() {
- length = (int) ((Math.random() * ((120 - 60) + 1)) + 60);
- jumps.add(length);
- }
- public void judge() {
- judges = new ArrayList<Integer>();
- if (judges.size() > 0) {
- judges.clear();
- }
- for (int i = 0; i < 5; i++){
- int temp = (int) ((Math.random() * ((20-10) + 1)) + 10);
- judges.add(temp);
- }
- }
- public void judgeSort() {
- int i = 1;
- Collections.sort(judges);
- while (i < 4){
- int points = judges.get(i);
- jTotal += points;
- i++;
- }
- }
- public ArrayList<Integer> listJudges() {
- return judges;
- }
- public int getLength() {
- return length;
- }
- public String getName() {
- return this.name;
- }
- public ArrayList<Integer> listJumps() {
- return jumps;
- }
- public int getjTotal() {
- return jTotal;
- }
- public int getTotal() {
- int temp = 0;
- for (Integer jump : jumps) {
- temp += jump;
- }
- return temp + jTotal;
- }
- @Override
- public int compareTo(Participants people) {
- return this.jTotal - people.getjTotal();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement