kashdkjaf
[rmh3093.git] / lab5 / act2 / TournamentMaker.java
blob698f603ffd668bbf7f1d3460e0ac8686ae05a58a
1 import java.io.*;
2 import java.util.ArrayList;
3 import java.util.Collections;
4 import java.util.LinkedList;
6 /*
7 * TournamentMaker.java
9 * Version:
10 * $Id: TournamentMaker.java,v 1.1 2008/04/15 21:33:13 rmh3093 Exp rmh3093 $
12 * Revisions:
13 * $Log: TournamentMaker.java,v $
14 * Revision 1.1 2008/04/15 21:33:13 rmh3093
15 * Initial revision
19 /**
20 * This class reads in team data for all of the teams in a tournament, stores
21 * teams in some form of linear list, prints out information about each of the
22 * teams in the order in which the data was entered, reorders the list so that
23 * teams are in order on the basis of number of wins (the team with the most
24 * wins occurs earliest in the list), prints out information about the teams
25 * based on the revised order of the list, and then sets up and prints the
26 * first round matches for a round-robin style tournament, in which the team
27 * with the most wins plays the team with the fewest wins, the team with the
28 * second most wins plays the teams with the second fewest wins, and so on.
30 * @author Ryan Hope
33 public class TournamentMaker {
35 public TournamentMaker() {
39 /**
40 * Method that reads in team data, stores data in a linear list, prints
41 * the data in the original list, reorders the data in the list on the
42 * basis of number of wins, prints the reordered list, and then sets up a
43 * round-robin style tournament, printing all the first round match-ups.
45 * @param numberOfTeams number of teams in the tournament
46 * @throws IOException can throw an exception if valid input file is not
47 * found
49 public void make(int numberOfTeams) throws IOException {
50 System.out.println();
51 System.out.println("Tournament Maker");
52 System.out.println("Read in " + numberOfTeams + " team names, number " +
53 "of wins, and strength of schedule\n");
54 System.out.println("Teams may be entered in any order\n");
55 LinkedList<Team> list = new LinkedList<Team>();
56 InputStreamReader reader = new InputStreamReader(System.in);
57 BufferedReader input = new BufferedReader(reader);
58 while (input.ready()) {
59 String[] data = input.readLine().split(" ");
60 Team team = new Team(data[0], Integer.parseInt(data[1]),
61 Integer.parseInt(data[2]));
62 list.add(team);
64 for (Team t : list) System.out.println(t);
65 System.out.println();
66 Collections.sort(list);
67 for (Team t : list) System.out.println(t);
68 System.out.println("\nThe first round matchups are:");
69 int numGames = numberOfTeams / 2;
70 for (int i=0; i<numGames; i++) {
71 int gameNum = i + 1;
72 int chalNum = numGames - i;
73 System.out.println("Game " + gameNum + " is " +
74 list.getFirst().getTeamName() + " against " +
75 list.getLast().getTeamName() + "\nwith the winner to " +
76 "play the winner of game " + chalNum);
77 list.removeFirst();
78 list.removeLast();