Copyright RIT 2008
$Id: writeup.xml,v 1.12 2009/10/02 15:21:08 vcss232 Exp $
In this lab you'll develop a solution to a problem that involves creating and manipulating a list. As a part of what you need to do, you'll obtain practice navigating or iterating through a list. You'll also experiment with several ways of arranging data in your list.
You are to work on this lab completely on your own.
As you now know, Java provides programmers with an extensive general-purpose library, part of which is known as the Java Collections Framework (/usr/local/jdk/docs/technotes/guides/collections/index.html) , or JCF. In this lab, we're going to make use of some of the ideas contained in the JCF to model a common situation.
In many sports (for example, think of basketball at the national level or bowling or darts at a local level), people often organize a tournament at the end of a season. Teams are seeded within a tournament on the basis of the number of wins during the regular season. By placing teams in some type of list on the basis of the number of wins, it becomes relatively easy to create the first-round matches for such a tournament. We select the team that is first in the list (i.e., the team with the most wins) and pair it with the team last in the list (i.e., the team with the fewest wins). If we remove the teams that had been first and last in our list, we can repeat the process to get the next pairing, and so on, until we have no more teams in the list.
Notice that we have to place some constraints on the number of teams entered in a tournament in order to have things "work out evenly" (otherwise, we'd have to deal with some teams that receive a bye in the first round of the tournament). For the purposes of this lab, we'll insist that we have the "proper" number of teams just to keep things simple.
Read this entire document to get an idea of the problem, the nature of the solution design that we have developed, the code that will be supplied to you to use, and the code that you will write.
Read the java documentation for the classes Collection, List, LinkedList, ArrayList, Collections, Iterator, Comparator, and Comparable.
Review your class notes on Collections.
Review last week's lab.
Fetch the materials for this lab from jar file and "unjar" them into an appropriate working directory.
Read the javadoc descriptions for the main classes involved
in this lab; namely, Team,
Tournament, and
TournamentMaker.
For this activity, you will only be writing the Java code
to implement the Team class, but you'll be
able to test your code by using the class files
included in the jar file.
Create a subdirectory called act1 and place
a copy of Tournament.java, the TournamentMaker.class
and the datafile from the jar file.
Don't forget to also create an RCS directory in here
for version control. You should do all your work in this act1
directory for this activity.
The javadoc gives you much of the information you need, but we also want you to think about some aspects of what you're doing. The following "hints" may also prove helpful.
equals() method should return
true if both objects have all the same
data. It is a general rule that if two
objects are equal, then their
compareTo() calls
should be 0.
toString() method
should be:
"team: (team-name) has: (# wins) wins
under a schedule whose strength was rated:
(strength) out of 10." Make careful note
of the spacing.
Once you have written your Team class,
you can run the overall Tournament program to test it.
The Tournament is run as follows:
|
where number is a whole number representing the number of teams to be entered into a tournament and datafile represents the name of a data file that contains input information about teams. Each line in a datafile consists of the name of a team, the number of wins during the season, and a whole number between 0 and 10, representing the team's strength of schedule, with each item separated from the next by a space. For the purposes of this lab, you may assume that information contained in a data file is correct. We have provided you with one data file for 8 teams, but you should feel free to create your own data files for testing.
When you are convinced that everything is working correctly, submit your code as follows:
try grd-232 lab5-1 Team.java
Reread the javadoc description of the TournamentMaker class, then write the Java code to implement the class. You'll be able to test your code by using some of the files included in the jar file.
Create a subdirectory called act2 and place
copies of the appropriate files from the previous
activity in this activity's working directory.
When you execute this program, the main program first
checks that the number of teams is appropriate. If not,
an error message is printed to standard error
and the program halts. If the number is valid, then
an object of type TournamentMaker is
created and its make() method is invoked.
Notice that we have also deliberately kept exception
handling to a minimum. For example, the
datafile that is referred to on the command line
may not be readable. Rather than worry about
all of the possibilities, we simply allow our program
to throw a general exception. We've done
this so as to not obscure the main purpose of the lab.
The javadoc gives you much of the information that you
need to write TournamentMaker, but we also
want you to think about some aspects
of what you're doing. The following "hints" may also
prove helpful.
Scanner object that is connected
to standard input. Look up the
javadoc for the Scanner
class to find the methods you need to use
in order to read the input data (recall that you
know exactly what the format is for data files
and can assume the file will be correctly formatted).
Team class the way we did).
The format for the team match output should be:
The first round matchups are:
Game 1 is (team) against (team)
with the winner to play the winner of game (number)
Game 2 is (team) against (team)
with the winner to play the winner of game (number)
...
If the following input file is used:
|
The output of the program would be as follows:
|
When you are convinced that everything is working correctly, submit your code as follows:
try grd-232 lab5-2 TournamentMaker.java
Read the javadoc description of the TeamComparator class, and then write the Java code to implement the class. You'll be able to test your code by using some some of the files included in the jar file.
Create a subdirectory called act3 and place
copies of the appropriate files from the previous
activity in this activity's working directory.
We admit that this seems a bit far-fetched. Rather than
ordering teams based on the number of wins, we ignore the
number of wins and base our rankings only on strength of
schedule. (Wouldn't it be nice if students could rank
courses on the basis of "hard" or "easy", with grades
based only on the rankings, not exams or other
course-related tasks?!) In order to make use of your
comparator, you'll have to figure out how to change
the code in the TournamentMaker class
(hint: it should only be one line that needs to be
changed).
Using the same input file
from the previous activity,
the output of the program would be as follows:
|
When you are convinced that everything is working correctly, submit your code as follows:
try grd-232 lab5-3 TeamComparator.java TournamentMaker.java
Grade Breakdown: