Class BaseStat

java.lang.Object
  extended by BaseStat

public class BaseStat
extends java.lang.Object

This class implements a mutable baseball player statistic object. The object maintains a player's hitting statistics: number of official at-bats, walks, hits, and total bases.


Constructor Summary
BaseStat()
          This constructor creates a BaseStat object with all statistics set to 0.
 
Method Summary
 java.lang.String addDouble()
          The method modifies the object by adding a double to the player's statistics.
 java.lang.String addHomer()
          The method modifies the object by adding a home run to the player's statistics.
 java.lang.String addOut()
          The method modifies the object by adding an out to the player's statistics.
 java.lang.String addSingle()
          The method modifies the object by adding a single to the player's statistics.
 java.lang.String addTriple()
          The method modifies the object by adding a triple to the player's statistics.
 java.lang.String addWalk()
          The method modifies the object by adding a walk to the player's statistics.
 int getBatAvg()
          This method returns this object's batting average.
 int getOnBaseAvg()
          This method returns this object's on-base average.
 int getSlugAvg()
          This method returns this object's slugging average.
 java.lang.String toString()
          This method returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BaseStat

public BaseStat()
This constructor creates a BaseStat object with all statistics set to 0.

Method Detail

addOut

public java.lang.String addOut()
The method modifies the object by adding an out to the player's statistics. An out counts as an official at-bat but nothing else.

Returns:
The string "out"

addWalk

public java.lang.String addWalk()
The method modifies the object by adding a walk to the player's statistics. A walk does not count as an official at-bat and it does not count as a hit.

Returns:
The string "walk"

addSingle

public java.lang.String addSingle()
The method modifies the object by adding a single to the player's statistics. A single counts as an official at-bat, a hit, and as one total base.

Returns:
The string "single"

addDouble

public java.lang.String addDouble()
The method modifies the object by adding a double to the player's statistics. A double counts as an official at-bat, a hit, and as two total bases.

Returns:
The string "double"

addTriple

public java.lang.String addTriple()
The method modifies the object by adding a triple to the player's statistics. A triple counts as an official at-bat, a hit, and as three total bases.

Returns:
The string "triple"

addHomer

public java.lang.String addHomer()
The method modifies the object by adding a home run to the player's statistics. A home run counts as an official at-bat, a hit, and as four total bases.

Returns:
The string "home run"

getBatAvg

public int getBatAvg()
This method returns this object's batting average. Batting average is 1000 times the number of hits divided by at-bats. If there are no at-bats, the average is 0.

Returns:
The batting average

getSlugAvg

public int getSlugAvg()
This method returns this object's slugging average. Slugging average is 1000 times the number of total bases divided by at-bats. If there are no at-bats, the average is 0.

Returns:
The slugging average

getOnBaseAvg

public int getOnBaseAvg()
This method returns this object's on-base average. On-base average is 1000 times the number of hits+walks divided by at-bats+walks. If at-bats+walks is 0, the average is 0.


toString

public java.lang.String toString()
This method returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
A string representation of the object