CS 2102 - Dterm 14

Homework 4 - Extending Tournaments

Due: Tuesday, April 1 at 5pm


This assignment is to be done individually. Read the Expectations on Homework.

For this and all remaining homework assignments, you should create a project where each class and interface is defined in a separate file (you did this in Lab 2). DrJava users should create a .zip file containing the java source files (under Project, choose "Create Jar File from Project", and in the next window check "java source files". Use .zip as the extension on your filename). Eclipse users can go to the JavaWorkSpace folder and create a zip file of the project.

Assignment Goals


Data Definitions

  1. If you're starting with your copy of Homework 2, start with a clean Examples class (no examples, no test cases). Remove all signatures (obligations) from the ITournament and IScores interfaces, and the implementations of those methods from the classes that implement the interfaces.

  2. Add a new kind of score, for swimming, that implements IScore. The components of a SwimmingScore are the times of the two contestants.

  3. In Homework 1 and 2, MatchData consisted of the names (Strings) of the two contestants, and the score of the match. Modify MatchData so that instead of using a String to represent a contestant, you use the type IContestant, the way we developed it in class. Implement separate contestants for soccer, baseball, and swimming, subject to the following constraints:
  4. Provide examples of tournaments in your Examples class, based on these new data definitions.

Methods

Make sure you use the signatures as given on the class handout.

  1. Write a method winner() on scores that consumes two contestants (in order, i.e. the first contestant parameter had the first score, and the second contestant parameter had the second score) and returns the name of whichever contestant won that match. Note that the winner for Swimming is the contestant with the shorter time. If the score for a particular sport is a tie, return the name of one of the contestants (it doesn't matter which name is returned).

  2. Write a method winner() on MatchData, that produces the name of the contestant that won the match (in the case of a tie, it doesn't matter which name is returned).

  3. Develop a method hasBetterRanking() for all ranked contestants that consumes another ranked contestant and determines whether this contestant is ranked better than the given contestant. Lower numbers represent better ranks.

  4. Tournaments are clearly binary trees. An obvious invariant for a tournament is that the tree be perfectly balanced (i.e. the heights of the left and right subtrees are the same for any given node). Write a method isBalanced on tournaments that returns true if the tournament is perfectly balanced, and false otherwise.
Make sure you provide tests for all new methods in your Examples class.

Grading

Here is the general grading rubric for the assignments in this course.

Programs must compile in order to receive credit. Programs must run in order to receive credit for Examples and Test Cases. Code that is commented out will not be graded.

What to Turn In

Using web-based turnin, submit .java files (as a .zip file) containing the final versions of all classes, interfaces, and examples developed for this assignment. Do not submit the .class files.