CS 2102 - D-term 14

Homework 2 - Designing with Methods in Java

Due: Tuesday, March 25 at 5pm


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

Assignment Goals


Problems

    Data definitions in Java

  1. Develop Java class and interface definitions that implement the hierarchy we developed for tournaments. Define an Examples class, and include examples of data for each class in your hierarchy. Tournaments should be created using the same type of sport for all matches (i.e., a tournament of soccer matches, or a tournament of baseball matches). Your program should have a Main method as described on the syllabus. Make sure that your program compiles and runs at this point before you try doing the remaining problems.

    Method definitions in Java

    Make sure you use the method signatures given on Friday's class handout. We will be running automated test scripts on your programs, which are dependent on those signatures. If your program fails the tests because you named your methods differently, points will be deducted from your homework score.

  2. The rules within a sport often imply that scores satisfy certain constraints. For example, baseball games require that at least 9 innings be played, and that the score may not end in a tie.

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

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

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

  4. Write a method matchesPlayedBy() on tournaments that consumes a contestant name and produces the number of matches in the tournament in which the named contestant played.

  5. Our description of tournaments says that the winner of each match advances to the next round. Nothing in our data definitions, however, requires this: our examples could have an error in which the loser of a match (or worse, a contestant that didn't even play in the match) advanced. Write a method winnerAlwaysAdvanced on tournaments that produces a boolean indicating whether each contestant in a match was the winner of one of the feeder matches (for initial matches, this method should produce true).

Grading

Here is the general grading rubric that will be used for all assignments in this course. There will be specific additional requirements for each particular assignment.

Homework that does not compile will earn a grade of 0. Homework that does not run will earn no credit for Examples and Test Cases. It is not unreasonable to ask that the work you turn in compiles without errors. If you develop your program incrementally, and thoroughly test each method before you go on to the next, you will be able to take care of errors as they occur. It is in your best interest to make one last check that your homework compiles just before you submit it. You will be graded on

What to Turn In

Using web-based turnin, submit .java files containing the final versions of all classes, interfaces, and examples developed for this assignment. Do not submit the .class files. You may submit either a single .java file containing all classes and interfaces, or, if you organized your homework as a project, submit a .zip file containing the .java files for each class/interface.

Failure to follow these instructions for submission will result in deductions on your homework score.