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 (Standard)

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).

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)

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

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 robot is (make-robot string boolean string)

(define-struct robot (school competed-before? best-feature)

1 Part 1: Creating Tournament Data

  1. Develop Java class and interface definitions to capture tournaments with the contents of the Scheme/Racket definitions shown above. Your tournaments definition should be able to support each of our three examples of tournaments (cricket, cooking, and robotics).

  2. Develop Java class and interface definitions for each of cricket teams, chefs, and robots, each with the contents of the Scheme/Racket definitions shown above.

  3. 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.

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

For the first deadline (on Friday), submit the definitions and examples from this part in turnin. You will be able to revise your work once you get to the methods – this deadline is a checkpoint on how you are approaching the assignment.

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. Competitions usually have a notion of an "underdog": a contestant who is unlikely to win many matches. Cricket teams with ranks larger than 20 (such as 21) are underdogs. Chefs with fewer than 100 twitter followers are underdogs. Robots that have not competed before and have "pogo sticks" as their best feature are underdogs.

    Edit your class and interface definitions as needed to require that every kind of contestant support an isUnderdog method. Include this method (with the definitions just given) in each of your contestant classes.

  2. Write a method countUnderdogWins on Tournaments on that produces the number of matches in the tournament in which the winner is an underdog.

  3. 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.

  4. 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.

  5. 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. 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.