← back to the schedule


Tournament — Initial Match-ups PROJECT
By Alyce Brady




PROBLEM DESCRIPTION

In this project you will implement a program to read tournament participants (for example, tennis players or basketball teams) in from a file along with their rankings, print that information sorted by ranking, and determine initial match-ups. In general, match-ups pair the highest-ranked participant with the lowest-ranked participant, the second highest-ranked participant with the second lowest-ranked participant, and so on.

If the number of participants is not an even power of two, then there will be an initial round involving only some participants in order to get the number of match-ups to an even power of 2; the highest-ranked participants will have a bye for the first round. The second round would then have a full complement of participants. For example, if there are 68 teams in a tournament, the first round (the bye round would consist of only the 8 lowest-ranked teams, with the other 60 teams having a bye for the first round. The four winners of the bye round would then join the other 60 teams for a full round of 64 teams participating in 32 matches. In a less-realistic but shorter example of a tournament with 3 participating teams, the top-ranked team would have a bye for the first round and would then play the winner of the other two teams. The table below compares this scenario against a single match-up between 2 teams with no bye.

Example with ByesExample with no Byes
Initial Rankings:
1. S Carolina
2. UConn
3. UCLA

Number of Rounds: 2
Number of Byes: 1

First-Round Byes:
1. S Carolina
----------------
Round 1 Match-Ups:
2. UConn vs. 3. UCLA

Round 1 Scores:
2. UConn (78) vs. 3. UCLA (64)
----------------
Round 2 Match-Ups:
1. S Carolina vs. 2. UConn

Round 2 Scores:
2. UConn (82) vs. 1. S Carolina (59)
Initial Rankings:
1. S Carolina
2. UConn

Number of Rounds: 1
Number of Byes: 0
----------------
Round 1 Match-Ups:
1. S Carolina vs. 2. UConn

Round 1 Scores:
2. UConn (82) vs. 1. S Carolina (59)

Getting Started

Most of the functionality for the Tournament program is in the Tournament class, although there are several other classes that represent participant information as (name, value) pairs, match-up assignments between participants, and classes that know how to read those values from files.

Download the files for the Tournament — Initial Match-ups Project:

  • Tournament.java — Contains most of the functionality of the program, including the main method. (Needs to be completed.)
  • ParticipantInfo.java — Represents (name, value) information about participants, such as their name and ranking. (Fully implemented)
  • ParticipantReader.java — An object that knows how to read participant information from a file, one participant per line. (Fully implemented)
  • Matchup.java — Represents a pairing of two participants and their scores. (Fully implemented)
  • Round.java — Represents the match-ups in a single round of the tournament, including scores after the match has been played. (Fully implemented)
  • ScoresReader.java — An object that knows how to read participant scores from a file, two participants per line. (Needs to be completed.)
  • ValidatedInputReader.java — Class with static methods that can prompt users for numeric or string input. (Fully implemented)
  • There are two files containing sample rankings data: 18rankings.txt (18 participants, so byes are needed) and 16rankings.txt (16 participants, so no byes necessary).
  • There are two files containing sample score results: byeRoundScores.txt and fullRoundScores.txt.
  • You will also need your K_OrderedList class and any other classes it requires.

First Look: Reading and Running Code for Understanding

Start by reading the code, but don't try to read every detail at once. Start with the Tournament class. The Tournament class contains the main method at the bottom of the class -- what does it do?

The runTournament method is the main driver of the program, calling the following methods to perform subtasks:

  • getRankings
  • setRoundsAndByes
  • generateFirstRound (which in turn calls determineMatchups)
  • simulateRoundOfPlay
  • getWinners

Where is the runTournament method? In general, (leaving main aside), are the methods laid out in a top-down or a bottom-up fashion? Note that some of the methods in the Tournament class are fully implemented, while others have code missing or commented out.

Does the Tournament class have many instance variables that are shared among all of the methods? One of the first methods that the runTournament method calls is getRankings. Are the rankings only used within getRankings, or are they communicated back to runTournament, and if so, how?

Before diving more deeply into all the details of the Tournament class, glance at the 18rankings.txt file and round1Scores.txt to see what the format is of the data being used by the program. Run the program to see what it does with the data. Look back at runTournament and getRankings and notice which blocks of code are commented-out or missing and which are not. Does the initial behavior of the code make sense to you based on your initial look at the runTournament and getRankings methods?

Next, look at the ParticipantInfo class, which is fully implemented. This class keeps track of the ranking, name, and most recent score for each participant. It has the usual getter methods, and one setter to set the score. (A participant's ranking and name do not change during the course of a tournament.) The class also redefines the toString method to always return a participant's ranking and name together, and provides a nameAndScore method that adds the participant's most recent score to that. Finally, it redefines the equals and compareTo methods. ParticipantInfo instances are considered equal (they refer to the same participant) if they have the same name. To order participants by ranking, less-than and greater-than comparisons are based on that. (The method also redefines the hashCode method because it should always be redefined when redefining the equals method. Hash codes will be a future topic in this course.)


Making Modifications

Following the precepts and practices of Agile Development, you should start by making the smallest modifications you can, and test them before going on to other modifications. As you work on the program, your output should slowly look more and more like that in the Sample Output below.

You may complete the implementation of the Tournament and ScoresReader classes based only on the comments in the existing code and the Sample Output as a guide, or, if you prefer more detailed guidance, you may follow the guided directions provided here.


Guided Directions

(Display)


Sample Output

(Display)


Clean and Refactor

Follow this link to clean and refactor your comments and code.


Submission

Submit your completed program through Kit, under Tournament — Initial Match-ups Project.

Have fun! And if you have any questions remember I am available during office hours and the Collaboration Center folks are here for you as well!




← back to the schedule