LD07: Simple Sort due Wed 28 Feb 10:00

\begin{purpose}
In this assignment you will:
\begin{itemize}
\item Understan...
...tem Continue thinking about and using inheritance.
\end{itemize}
\end{purpose}

Preparation for Lab Day

Do these steps:
  1. In your workspace, make sure you have the latest homework files from the base repository. This will create a hw07 directory. Copy all source code from hw06 into hw07. We will be working in the hw07 directory.

  2. The String class defines a method called compareTo() that accepts another string as a parameter and returns an int based on how this string compares to the one passed as a parameter:
    • if this string is less than the parameter string then the value returned is some integer less than zero
    • if this string is greater than the parameter string then the value returned is some integer greater than zero
    • if this string is equal to the parameter string then the value returned is zero

    So, to determine how one string compares to another we call the compareTo() method.

  3. For this pre-lab assignment you will create a compareTo() method for the RPSPlayer class that will accept another RPSPlayer object as a parameter and will return an int according to these rules:
    • if this RPSPlayer is less than the parameter RPSPlayer then the value returned is some integer less than zero
    • if this RPSPlayer is greater than the parameter RPSPlayer then the value returned is some integer greater than zero
    • if this RPSPlayer is equal to the parameter RPSPlayer then the value returned is zero

    As you can see the behavior will be nicely parallel to the behavior the the String class compareTo(). The big question at hand is this: “What does it mean for an RPSPlayer to be less than or greater than another RPSPlayer?”

    We may answer this differently at different times, but for now use this definition: an RPSPlayer is less than another RPSPlayer if its name appears earlier in the alphabet than the other player's name.

  4. Once your compareTo() method is compiling test it by creating a driver that demonstrates it for less than, greater than, and equal to.

  5. Commit and push your changes.

Lab Day

Begin by showing your prelab work to the instructor. Then do these steps:

  1. In your workspace make sure you have the most recent code from the base repository and from your homework repository on bitbucket.

  2. We are going to create an RPSTournament class with this functionality:

    RPSTournament
    – RPSPlayer [] players array of RPS players
    – int numPlayers number of players in array
    + RPSTournament() constructor reserves memory in array
    + void add(RPSPlayer) add a player to the roster
    + void display() display list of all players in the roster
    + int size() return number of players in roster
    + void sort() sort roster
    + void play() have players face off in some arrangement

    Before you start writing code it would be helpful to remember that you already have an RPSPlayerContainer that provides most of this functionality. The question that looms is whether to inherit or to instantiate. That is, do we say that an RPSTournament IS-A RPSPlayerContainer or that an RPSTournament HAS-A RPSPlayerContainer?

    I think you could make a compelling argument for each which makes this a fine example of a scenario you could easily encounter when solving any real-world problem ... blurry lines! In class you were advised: “When in doubt, don't inherit!” However, since we are trying to learn and practice inheritance we'll inherit!

  3. Draw a UML diagram that shows both RPSPlayerContainer and RPSTournament in accordance with our proposed design. Show the UML diagram to the instructor.

  4. In the hw07 directory create a new class called RPSTournament and have it inherit from RPSPlayerContainer. You'll notice that by inheriting we automatically endow our new class with all of the attributes and methods we need with the exception of sort() and play(). Go ahead and add JavaDoc comments for your new class.

  5. Have the constructor of the new class call the parent class constructor. Then add documentation for the constructor.

  6. Modify (or create if necessary) a driver that will create an instance of the new class. You should add five players to the instance and then display them. Document the changes to your driver. Then add your changes to the git repository and commit them.

  7. Create a sort() method that will use a simple selection sort to order the list of players. To compare one player to another call the compareTo() method you wrote in the pre-lab exercises.

  8. Test the new sort() method by calling it from the driver and then displaying the list. Once it is working add documentation to the method and commit your work.

  9. Show your work to the instructor. Be sure to push your latest commit to your bitbucket repository.

  10. If you finish early begin work on the homework assignment.