1 Data Definitions
2 Valid Tournaments
3 Reflecting on Your Work
4 What to Turn In
5 Grading

Assignment 2: Extending Tournaments

Start from your Tournaments assignment from last week. Your class definitions from included tournaments and scores, distinguishing between scoring details for soccer, baseball, and tennis. This week, we extend the example to capture additional differences among these sports that arise in tournaments.

1 Data Definitions

Different tournaments have different notions of contestants: baseball and soccer are team sports, while tennis is an individual sport (we’ll ignore doubles). Soccer and tennis both track rankings (so top-ranked competitors won’t face each other in an early tournament round). This week, we extend our model of tournaments to capture both team sports and ranked sports.

Your task is to edit your class hierarchy from last week to include baseball, soccer, and tennis contestants subject to the following constraints:

2 Valid Tournaments

Tournaments are clearly binary trees. In class, we studied different types of binary trees with different invariants. What are the invariants of tournaments?

Although we have not written programs to create tournaments, we could imagine wanting to test that programs that do create tournaments produce valid ones. Your task here is to create an hasInvariant method on tournaments that returns a boolean indicating whether the tournament meets all three of these invariants.

How you do this is up to you. We recommend writing separate methods per invariant, though. You will not be graded on the efficiency of hasInvariant (so multiple traversals over the tournament tree is fine). We care more about your having captured the invariants cleanly and in properly handling the fact that one invariant (on rankings) applies to only some tournaments but not others.

Extend your Examples class as appropriate for your new data definitions and methods.

3 Reflecting on Your Work

Answer these questions in a text file called questions.txt.
  1. Does your data definition formally capture that soccer and tennis contestants are similar in having ranks? If yes, how? If no, what change to your code would achieve that?

  2. How do you enforce the requirement that a ranking must be larger than zero?

  3. Does your implementation of hasBetterRanking require the two contestants to be in the same sport? How or why not? (You don’t have to change your code to achieve this – credit is based on your answering the question in accurate technical terms relative to your code.

  4. How does your hasInvariant implementation handle the additional invariant on ranked tournaments without duplicating common code about all valid tournaments?

4 What to Turn In

Submit your .java files along with a text file question.txt with your answers to the extension questions. Do not submit the .class files. You may submit either a separate file for each class/interface (standard for Java) or a single file containing all classes and interfaces.

5 Grading

Grading will follow the standard rubric. We will focus on issues new to this week’s code, but you should correct problems from last week’s assignment that affect this week’s assignment.