1 Part 1: Creating Tournament Data
2 Part 2: Methods
3 What to Turn In
4 Grading and Expectations

Assignment 1: Modeling and Implementing Tournaments (Advanced)

Due (part 1): Friday, March 20 at 5pm via Turnin

Due (part 2): Tuesday, March 24 at 11:59pm via Turnin

This assignment will be posted and due in two parts: a first part will be due on Friday, with a second part due on Tuesday. We will post the second part only after the first part comes in, so check back on Friday for the rest of the assignment (it will build off of the first part).

Part 1 must be done and submitted indvidually. You will be allowed to work with a partner for part 2. If you work with a partner, both of you must have had prior Java experience.

This is a more challenging version of the standard assignment on tournaments. While it does not assume material beyond what we have done in class, it exercises that material at a deeper level. Enjoy!

Many tournaments are organized into elimination rounds, in which pairs of remaining contestants play a match and the winner advances onto the next round. In this assignment, we will model and implement programs over tournaments in Java.

The following Scheme/Racket data definitions capture tournaments:

;; A tournament is either

;; - (make-init-match match-data)

;; - (make-advance-match match-data tournament tournament)

(define-struct init-match (data))

(define-struct advance-match (data feeder1 feeder2))

 

;; a match-data is (make-match-data contestant contestant contestant score)

(define-struct match-data (side1 side2 winner score))

Different kinds of tournaments capture different information about the contestants. The Cricket World Cup (going on right now!) features internationally-ranked contestants who compete as a nation:

;; a cricket-team is (make-cricket-team string string number)

(define-struct cricket-team country jersey-color rank)

A reality-cooking show, in contrast, features chefs who compete individually:

;; a chef is (make-chef string string number)

(define-struct chef (name cuisine twitterFollowers)

An inter-university robotics tournament might care about the interesting special capabilities of each robot (such as a powerful arm, rocket-powered jumping, or the ability to spray water):

;; a tennis-player is (make-tennis-player string number)

(define-struct tennis-player (name ranking))

This set of examples captures different notions of contestants: cricket is a team sport, but chefs and tennis players compete as individuals. Both cricket teams and tennis players are ranked, but chefs are not.

Each tournament also has a different notion of scoring. In a cricket match, each side’s score is reported as two numbers: the number of runs and the number of players who were out before the game ended. Cooking competitions give a single number from 0 to 10. A simple version of tennis scores simply reports the number of sets won by each player.

1 Part 1: Creating Tournament Data

  1. Create the Java classes and interfaces needed to capture tournaments as defined by the Racket definitions above (including contestants and scores). Contestants could be teams and/or ranked (or neither). Each ranked contestant must have a ranking. Each team contestant must be able to report a name for the team.

  2. Create several examples of data (in an Examples class) for tournaments. Use each of the three kinds of contestants across your set of examples. Think ahead to variations in the tournaments that might become useful once we ask you to write methods over tournaments for part 2.

  3. Think about how you will capture a tournament that has started, but not yet finished, so winners are not yet known for all matches.

2 Part 2: Methods

We will run our own set of test cases against your work as part of grading this assignment. This will only work if everyone has used the same names for the classes, interfaces, and methods. Edit your work from part 1 as needed to conform to the following naming conventions:

To help you test whether your names are correct, use this Main.java (which detects naming errors).

Test cases are graded on this and all assignments unless an assignment states otherwise.

  1. The rules within a sport often imply that real scores satisfy certain constraints. For example, tennis matches never last more than 5 sets total (3 for women’s matches). We therefore want to write a function to check that scores are valid (by the rules of the corresponding competition).

    Write a method isValid on scores that determines whether the score is valid for its corresponding sport. In particular:

    • Cricket scores: The number of players out must be between 0 and 10 and the number of runs must be non-negative.

    • Chef scores: must be a real number between 0 and 10 (inclusive).

    • Tennis scores: the total number of sets won across the players must be no more than 3, with one player winning at least two (we’ll ignore the different number of sets for men’s and women’s matches in this assignment).

    Your code should require every score (even those for other sports that we might add later) to have an isValid method.

  2. Write a method allScoresValid on tournaments that determines whether every match in the tournament has a valid score.

  3. Just as games have rules that restrict valid scores, tournaments also have a notion of validity. For this assignment, we are interested in two conditions:

    • If a match has recorded a winner, then the winner played in the match. Write a method winnersAlwaysPlayed on Tournaments that produces a boolean indicating whether every match with a known winner has a winner that was also one of the sides in the match.

    • If a tournament is in progress, and some matches do not yet have winners, then no match has a winner unless its feeder matches have winners. Write a method anySkippedMatches on Tournaments that produces a boolean indicating whether any match with a known winner has a feeder match with an unknown winner.

  4. An image consultant for an upcoming cricket tournament wants a method named hasColorClash that works only on cricket tournaments and indicates whether two teams with same jersey color are ever scheduled in the same initial match.

    In text (as a comment) discuss whether it is possible to write such a method with (a) the rest of the definitions as you have them, and (b) the Java constructs we have covered so far. If you think it is possible, describe what helper methods you would need in which classes. If you don’t think it is possible, explain as precisely as you can why this can’t work in the portion of Java that you’ve learned so far. you do not have to submit any code for this question, just your analysis.

3 What to Turn In

Submit .java files containing the final versions of all classes, interfaces, and examples developed for this assignment. Do not submit the .class files. Put your Examples class in its own file called Examples.java. Your may put all of your other classes and interfaces either into a single file or into separate ones (as you prefer).

4 Grading and Expectations

Follow the General Formatting Guidelines on assignments. Here is an example of a well-formatted version of the animals programs from early this week.

This assignment will earn points towards the following course themes:

Here are some details on what we will look for in grading this assignment:

In previous years, typical submissions have lost the most points on inadequate test cases. This class takes test-case development seriously. A strong test suite indicates that you really understand both the data you are working with and the nuances of the problem. We grade your tests as closely as your code, so take time to think out your test cases and whether they really exercise both the data structure and the methods you are writing.