2 import java
.util
.ArrayList
;
3 import java
.util
.Collections
;
4 import java
.util
.LinkedList
;
10 * $Id: TournamentMaker.java,v 1.1 2008/04/15 21:33:13 rmh3093 Exp rmh3093 $
13 * $Log: TournamentMaker.java,v $
14 * Revision 1.1 2008/04/15 21:33:13 rmh3093
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.
33 public class TournamentMaker
{
35 public TournamentMaker() {
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
49 public void make(int numberOfTeams
) throws IOException
{
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]));
64 for (Team t
: list
) System
.out
.println(t
);
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
++) {
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
);