
/* Generated by Interface Builder */

#import "Car_main.h"
#import "GasTank.h"

@implementation GasTank

- init
{
    [super init];
    gasTank = self;
    return self;
}

- read:(NXTypedStream *)stream
{
    [super read:stream];
    NXReadTypes(stream,"dffff",&current,&energyDensity,&fuelDensity,&mass,&max);
    return self;
}

- write:(NXTypedStream *)stream
{
    [super write:stream];
    NXWriteTypes(stream,"dffff",&current,&energyDensity,&fuelDensity,&mass,&max);
    return self;

}

- (double)current
{
    return current;
}

- setCurrent:(double)aNumber
{
    current = aNumber;
    return self;
}

- (float)energyDensity
{
    return energyDensity;
}

- setEnergyDensity:(float)aNumber
{
    energyDensity = aNumber;
    return self;
}

- (float)fuelDensity
{
    return fuelDensity;
}

- setFuelDensity:(float)aNumber
{
    fuelDensity = aNumber;
    return self;
}

- (float)mass
{
    return mass;
}

- setMass:(float)aNumber
{
    mass = aNumber;
    return self;
}

- (float)fuelMass
{
    return (current * fuelDensity);
}

- (float)max
{
    return max;
}

- setMax:(float)aNumber
{
    max = aNumber;
    return self;
}

/******************************************************************************************************************************
 *    Here is where the actual work gets done.  Not very much, is it?                                                         *
 ******************************************************************************************************************************/
- energyRequired:(float)energy
{
float volumeUsed;

    energy /= 1000;			// Remember to convert from Joules to kiloJoules
    volumeUsed = energy / energyDensity;
    current -= volumeUsed;
    return self;
}

- getSetForRun
{
    startLevel = current;
    return self;
}

- finishedRun
{
    current = startLevel;
    return self;
}

- report:(NXStream *)stream
{
    NXPrintf(stream,"Gas Tank:\n");
    NXPrintf(stream,"  Fuel Used:%fL\n",startLevel - current);
    return self;
}

@end
