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:
In the Rugby World Cup (which is just wrapping up), contestants are teams each of which represents a country and wears a specific jersey color. A team may or may not have a formal intimidation ritual at the start of each match (this is a reference to the haka, the traditional pre-match ritual by the New Zealand team); just use a boolean to record whether a team has such a ritual. Each team has a certain number of wins and losses for the season.
Robotics competitions also feature teams. Each team comes from a particular school, and competes with a robot that has some special feature (such as a powerful arm or the ability to spray water, which we describe as a string). We also care about the numeric position/rank that the team had in their last competition (using 0 if a team has never competed before).
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:
A rugby score is just the number of points scored.
A robotics score contains a number of points, a number of attempted tasks, and an indication of whether the robot fell down during the competition.
2 Programming Problems
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.
Create several examples of data (in an Examples class), at least one for each kind of contest.
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.
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.
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.
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.
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.
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?
What about your code either allows or prevents this weird match?
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.
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.
Make your methods work with all of the fields marked private and without writing getters (methods that simply return the value of a field).
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:
Java Programming (whether you used the constructs properly)
Testing (the correctness and thoroughness of your tests)
Program Design (appropriate use of classes and interfaces, documentation, clean code)
Here are some details on what we will look for in grading this assignment:
Do your classes have appropriate variables and methods for the given problem?
Did you create an appropriate set of classes for the given problem?
Did you use interfaces where appropriate?
Do your methods have appropriate parameters for the given problems?
Do your methods produce the right answer?
Is your code well documented, with brief purpose statements on each method?
Is your code indented and presented in a clean, readable manner?
Are your test cases thorough, covering possible variations in the input data and exercising all of your code?
7 Updates and Clarifications
Here are answers to common questions or clarifications that came up based on the discussion forum:
If expectToBeat takes an IContestant, how can we check specific fields (such as win/loss rates) to write expectToBeat in each specific class?
This answer was updated on Monday 11/2 at 4pm
The question correctly observes that IContestant doesn’t give access to the fields of specific kinds of teams. We’d like to assume that Rugby Teams will only be compared to other Rubgy Teams (and similarly for robotics teams), but the types don’t say that. So the question is how can you put that assumption into your program?
Use the following pattern to address this problem. We will explain it in more detail in the coming days.
Assume your exptToBeat method had the following header:
public boolean expectToBeat(IContestant opponent) { ... }
(but with whatever name you want for the opponent parameter).
Now, everywhere you use opponent in the code, update it to include the name of the class that the opponent should come from, as shown below.
((RugbyTeam)opponent) // in the RugbyTeam class
((RoboticsTeam)opponent) // in the RoboticsTeam class
So opponent.ritual would become ((RugbyTeam)opponent).ritual, and so on.
If you had a different parameter name, use that instead of opponent here.
The parentheses here matter. Make sure you replace opponent with the entire term shown above, with both sets of parentheses.
We will only check your expectToBeat methods and tests for situations in which both teams are from the same kind of contest. You do NOT need tests that compare Rugby teams with Robotics teams.