1 Problem Description and Context
2 Programming Problems
3 Design Question
4 Advanced Problems (Optional)
5 What to Turn In
6 Grading and Expectations
7 Updates and Clarifications

Assignment 1: Modeling Matches and Contestants

Due: Tuesday, Nov 3 at 11:59pm via InstructAssist

For those with prior Java experience, we invite you to include the advanced extensions in section Advanced Problems (Optional).

Need help finding a homework partner? Fill in this form. We’ll do one round of assignment pairings on Friday afternoon and another on Sunday afternoon. After that, you will have to find your own partner if you want one.

See Setting up Partners for instructions on configuring your homework partner in InstructAssist.

1 Problem Description and Context

Many competitions are played as a collection of matches or contests between either individual players or teams. In this assignment, we will use Java to model and implement programs over single matches.

Each match involves two contestants and contains the results (the scores for each contestant). The details of contestants and scores differ across kinds of contests (sports, quiz shows, robot battles, etc), but the structure of a match does not.

For this assignment, we will consider two kinds of contestants:

The results of a match consist of the scores for each contestant. For purposes of this assignment, the following information makes up the score for a contestant in each kind of event:

2 Programming Problems

  1. Develop Java class and interface definitions to capture matches, contestants, and scores as described above. Your data should capture all of the italicized concepts from the description. You should have one match definition that can capture each of Rugby and Robotics matches, but different definitions for each kind of contestant and score.

    In order to let us run tests against your code, everyone needs to use standard names for interfaces and classes. Use the following:

    • IContestant, and IResult for interfaces

    • Match for the match class

    • RugbyTeam and RoboticsTeam for the contestant classes

    • RugbyResult and RoboticsResult for the results classes

    • You may structure the fields of the results classes however you wish, but your results-class constructors should take all of the components of the results for both players. This means the RugbyResult constructor should take two numbers (the points for each team) and the RoboticsResult constructor should have the following inputs (but you can do whatever you want with those inputs internally):

        RugbyResult(int team1points, int team2point) {

           ...

        }

        

        RoboticsResult(int team1points, int team1tasks,

                       boolean team1fell,

                       int team2points, int team2tasks,

                       boolean team2fell) {

           ...

        }

    Here is a custom Main.java file for hwk1 that will check whether your code has the expected names and types for classes and methods. Any compiler errors reported on this file point to naming or type errors in your code, not in this file.

  2. Create several examples of data (in an Examples class), at least one for each kind of contest.

  3. Write a method isValid on results that determines whether the individual score components are expected or reasonable values according to the kind of contest. Rugby scores should be under 150 points and robotics scores should have fewer than 8 attempted tasks and no more than 16 points.

  4. Write a method winner on matches that returns the contestant that won the match according to the results. You may assume that there are no matches with ties. The winner of a Rugby match is the team with more points. The winner of a robotics contest is the one with the highest sum of points and tasks, with a 5 point deduction if the robot fell down.

  5. Write a method expectToBeat on contestants that takes another contestant as input and returns a boolean indicating whether the contestant would be expected to win against the given/input contestant. For a rugby match, if only one team has an intimidation ritual, that team is the expected winner; if neither or both teams have such rituals, the expected winner is the one with a better win/loss ratio. The expected winner of a robotics competition is the one whose powerful feature has a longer description (i.e., is a longer string). If there is no clear expected winner, return false.

    See the updates section at the bottom of the page for a clarification on how to approach part of this problem.

  6. Write a method underdogWon on matches that returns a boolean indicating whether the contestant that did win was not the one that was expected to win.

  7. In your Examples class, include test cases for each of these methods, but pay particular attention to testing the expectToBeat method. We will grade your expectToBeat tests for how well they would catch reasonable but incorrect solutions to the expectToBeat problem.

3 Design Question

Submit a text file (not PDF, not Word, just plain text) with answers to the following questions.

  1. Using your definitions, can someone create a match in which a Rugby team competes against a Robotics team and the scores are for another kind of contest entirely?

  2. What about your code either allows or prevents this weird match?

  3. If your code does not prevent this, could it? How? (Don’t change your code to try to prevent this, just discuss whether you _could_ change your code to prevent this.)

4 Advanced Problems (Optional)

If you have prior Java experience and want a bit more of a challenge, add the following features to your solution. Advanced students don’t get extra credit, but you get a chance to push on your Java skills a bit (which hopefully will make the assignment more interesting for you). Your goal should be to handle these extra questions cleanly and well, not to just smash them into Java in whatever way will work. This is about using good design practice.

If you are new to Java, the wording of these questions likely won’t make sense. Don’t worry – you will get to these topics and issues before the end of the course.

  1. The data described above capture completed matches that have scores. What if you also want to capture pending matches that haven’t been played yet? Augment your work as needed to capture pending matches. Include an example of such a match in your Examples class.

  2. Make your methods work with all of the fields marked private and without writing getters (methods that simply return the value of a field).

  3. We’ve noted that some (but not all) contests are among players who are ranked. Assume we wanted to require every ranked contestant to support a method rankedLowerThan which takes another ranked contestant as input and compares their rankings. Augment your work to capture the notion of rankings and to make robotics teams ranked contestants (with the rankedLowerThan method). Your approach should support ranked contestants beyond robotics teams, though you don’t have to add any particular ranked contestants.

5 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). Please do NOT put any of your code in a package (meaning no package declarations in your file and no separate package folder).

Submit a single zip file containing all of your work. If you are using Eclipse and have separate src and test subdirectories, you may retain that structure in your zip file.

6 Grading and Expectations

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

This assignment will earn points towards the following course themes:

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

7 Updates and Clarifications

Here are answers to common questions or clarifications that came up based on the discussion forum: