Alright so I have a tester for this class and it keeps saying this message:
"Now testing your drive method:
*** A car with mileage of 700 miles driving 400 miles before running out of gas should not now have mileage of 1700.0 miles"
However when I remove the mileage or gasNeeded or gasInTank it will say the one that is there it is working, but not both!
Any help is appreciated!!
public class Car
{
private double mpg;
private double mileage;
private double tankCapacity;
private double gasInTank;
/**
Constructs a car.
@param miles miles per gallon that a car gets
@param milesOnCar total mileage on car
@param gasTankHolds amount of gas the tank holds
@param gasTankHas gas in tank now
*/
public Car(double miles, double milesOnCar,
double gasTankHolds, double gasTankHas)
{
mpg = miles;
mileage = milesOnCar;
tankCapacity = gasTankHolds;
gasInTank = gasTankHas;
}
/**
Returns the current mileage on the car.
@return mileage on car
*/
public double getMileage()
{
return mileage;
}
/**
Returns the amount of gas in the gas tank.
@return amount of gas in tank
*/
public double getGasInTank()
{
return gasInTank;
}
/**
Returns the gas needed to drive miles (based on mpg)
@param numMiles the number of miles to be driven
@return gas needed to drive numMiles miles
*/
public double gasNeeded(double numMiles)
{
double gasNeeded = numMiles/mpg ;
if(numMiles == 0)
{
return 0 ;
}
else if(mpg == 0)
{
return 0 ;
}
else
return gasNeeded ;
}
/**
Returns true if the car has enough gas in the tank to
drive numMiles, otherwise returns false.
@param numMiles miles to be driven
@return true if gas in tank is enough to drive numMiles
miles; false otherwise.
*/
public boolean enoughGas(double numMiles)
{
double gasNeeded = numMiles/mpg ;
if(gasInTank == gasNeeded)
{
return true ;
}
else
{
return false;
}
}
/**
If tank is less than half full, fills tank and updates
gasInTank. Otherwise does nothing.
*/
public void getGas()
{ double gas2 = 1.0/2.0 * tankCapacity ;
if(gasInTank <= gas2)
{
gasInTank = tankCapacity ;
}
}
/**
Updates mileage and gasInTank to reflect numMiles
being driven.
@param numMiles number of miles driven
*/ /**
Updates mileage and gasInTank to reflect numMiles
being driven.
@param numMiles number of miles driven
*/
public void drive(double numMiles)
{
double gasNeeded = numMiles/mpg ;
if(numMiles != 0 )
{
mileage = mileage + numMiles ;
}
if(gasInTank> gasNeeded)
{
gasInTank = gasInTank - gasNeeded ;
}
if(gasInTank < gasNeeded){
gasInTank = 0 ;
}
}
}