So, to determine how one string compares to another we call the compareTo() method.
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.
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!