gamekeeper2a
Class SimpleGamekeeper

java.lang.Object
  |
  +--gamekeeper2a.SimpleGamekeeper
Direct Known Subclasses:
BaseballGamekeeper, GolfGamekeeper

public abstract class SimpleGamekeeper
extends java.lang.Object

Keep track of matches that have been played.


Constructor Summary
SimpleGamekeeper()
          Creates a new instance of SimpleGamekeeper.
 
Method Summary
protected  boolean acceptGameResults(IGameResult mresult)
           
abstract  boolean acceptGameResults(java.lang.String gameString)
          Remember the results of a match.
 boolean acceptGameResults(java.lang.String resultsString, boolean highScoreWins)
           
abstract  boolean acceptGameResults(java.lang.String contestant1, int contestant1Score, java.lang.String contestant2, int contestant2Score)
          Remember the results of a match.
 boolean acceptGameResults(java.lang.String contestant1, int contestant1Score, java.lang.String contestant2, int contestant2Score, boolean highScoreWins)
          Remember the results of a match.
 IContestant findContestant(java.lang.String contestantName)
          Given a contestant name, find the information about it.
 java.lang.String[] listContestantResults()
          Returns a string array giving information about all known contestants, exactly one contestant per array entry, in no particular order.
 java.util.ArrayList listContestants()
           
protected  boolean setGameResults(IGameResult gresult)
          Remember the results of a match.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleGamekeeper

public SimpleGamekeeper()
Creates a new instance of SimpleGamekeeper. At this point, no games are recorded, and no contestants are known.

Method Detail

findContestant

public IContestant findContestant(java.lang.String contestantName)
Given a contestant name, find the information about it. PRECONDITION: rawInfoString is not null

Parameters:
contestantName - the name to search for; surrounding spaces are ignored.
Returns:
the entry for the team with this name, if it is known, null if the team is not known.

acceptGameResults

public abstract boolean acceptGameResults(java.lang.String gameString)
Remember the results of a match. Information about the match is in a string with the following format: , The comma is required, and must immediately follow the first score (no intervening spaces). White space at the begining and ending of the winner or loser should be ignored. The two contestants must not be the same (after trimming spaces). String should be non-null.

Returns:
true if there were no errors detected and the information has been recorded; false if there were errors (in which case the information is not remembered.)

acceptGameResults

public abstract boolean acceptGameResults(java.lang.String contestant1,
                                          int contestant1Score,
                                          java.lang.String contestant2,
                                          int contestant2Score)
Remember the results of a match. White space at the begining and ending of the winner or loser should be ignored. For example, "Tyler", " Tyler", and " Tyler " should all be considered the same contestant. The two contestants must not be the same (after trimming spaces). Strings must be non-null.

Returns:
true iff all parameters are valid; return false if there is any error. In case of an error, nothing should be remembered about this case; for example, if one of the contestants was hitherto unknown -- it remains unknown.

acceptGameResults

public boolean acceptGameResults(java.lang.String contestant1,
                                 int contestant1Score,
                                 java.lang.String contestant2,
                                 int contestant2Score,
                                 boolean highScoreWins)
Remember the results of a match. The contestant with the larger score is the winner. White space at the begining and ending of the winner or loser should be ignored. For example, "Tyler", " Tyler", and " Tyler " should all be considered the same contestant. The two contestants must not be the same (after trimming spaces). Strings must be non-null.


acceptGameResults

public boolean acceptGameResults(java.lang.String resultsString,
                                 boolean highScoreWins)

acceptGameResults

protected boolean acceptGameResults(IGameResult mresult)

setGameResults

protected boolean setGameResults(IGameResult gresult)
Remember the results of a match. Winner and loser must not be the same (after trimming spaces). If the scores are the same, the game is considered a draw.

Returns:
true if the parameters are valid; false otherwise.

listContestants

public java.util.ArrayList listContestants()

listContestantResults

public java.lang.String[] listContestantResults()
Returns a string array giving information about all known contestants, exactly one contestant per array entry, in no particular order. The array has exactly one line (string) per contestant, with the contestant name at the beginning of the line, a space, followed by the number of games won, a dash, then the number of games lost. The line should be suitable for displaying on a console without any changes.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object