Class CarStat

java.lang.Object
  extended by CarStat

public class CarStat
extends java.lang.Object

This class implements a mutable class for keeping car race statistics on miles led, percent of miles led, and average finish. Each object represents one driver and his/her stats.


Constructor Summary
CarStat(java.lang.String name, int number)
          This constructor creates a CarStat object with a driver name and car number.
 
Method Summary
 double avgFinish()
          This accessor method calculates the average position of finish for this driver over the races in which the driver competed.
 java.lang.String getDriver()
          This accessor method returns the name of this driver.
 double getMilesLed()
          This accessor method returns the total miles led by this driver.
 double percentMilesLed()
          This accessor method returns the percent of miles led by this driver as a percentage of the total miles of all races.
static void setupRace(double lapLength, double miles)
          This mutator method sets the track size and distance data for a race and must be called before calling updateRaceStats to add statistics for that race to any object.
 java.lang.String toString()
          This method returns a string representation of this object.
 void updateRaceStats(int lapsLed, int position)
          This mutator method updates the individual driver statistics on laps led, average finish position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CarStat

public CarStat(java.lang.String name,
               int number)
This constructor creates a CarStat object with a driver name and car number. All other driver statistics are set to zero.

Parameters:
name - Driver name
number - Car number
Method Detail

setupRace

public static void setupRace(double lapLength,
                             double miles)
This mutator method sets the track size and distance data for a race and must be called before calling updateRaceStats to add statistics for that race to any object. Lap length will give the length of a single lab in miles (track size); miles indicates the total length of the race. This method must be called exactly once for each race run and increases the count of the number of total races.

Parameters:
lapLength - Size of the track in miles
miles - Length of race in miles

updateRaceStats

public void updateRaceStats(int lapsLed,
                            int position)
This mutator method updates the individual driver statistics on laps led, average finish position.

Parameters:
lapsLed - Number of laps that this driver led the race
position - Position number at end of the race

avgFinish

public double avgFinish()
This accessor method calculates the average position of finish for this driver over the races in which the driver competed.

Returns:
average finish position of this driver

percentMilesLed

public double percentMilesLed()
This accessor method returns the percent of miles led by this driver as a percentage of the total miles of all races.

Returns:
The percent of this driver's led miles

getMilesLed

public double getMilesLed()
This accessor method returns the total miles led by this driver.

Returns:
The miles led by this driver.

getDriver

public java.lang.String getDriver()
This accessor method returns the name of this driver.

Returns:
This driver's name.

toString

public java.lang.String toString()
This method returns a string representation of this object. The format of the string is: "Driver:%s, Car:%d, Races:%d, AvgFin:%f, MilesLed:%f"

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