public class Car extends java.lang.Object implements java.lang.Comparable<Car>
Class invariants:
Modifier and Type | Field and Description |
---|---|
static int |
FORWARD |
static int |
PARK |
static int |
REVERSE |
Constructor and Description |
---|
Car()
Create a car that gets 20 mpg and has a tank capacity of 10 gallons
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Car otherCar)
compare this car with otherCar to see which one is ahead (i.e.
|
void |
fillTank()
Fills the tank to the full capacity.
|
double |
getCapacity() |
int |
getGear() |
double |
getLocation() |
double |
getMPG() |
double |
getRemainingGas() |
void |
go(double miles)
Go for a specified distance (or as far as the current gas allows) in the current gear
|
void |
refuel(double fuelAmount)
Fills the gas tank with the given amount of gas, or enough to fill the tank, whichever is less.
|
void |
setGear(int newGear)
Sets the gear that the car will be in.
|
java.lang.String |
toString()
Used in printing the car's status.
|
public static final int PARK
public static final int FORWARD
public static final int REVERSE
public Car()
public void go(double miles)
precondition: car is in gear and has fuel, miles is non-negative
postcondition:
miles
- is the number of miles to gopublic void fillTank()
public void refuel(double fuelAmount)
precondition: fuelAmount is non-negative
postcondition: remainingFuel = min(tankCapacity, remainingFuel' + fuelAmount)
fuelAmount
- is the amount of fuel to addpublic double getRemainingGas()
public double getCapacity()
public double getLocation()
public double getMPG()
public int getGear()
public void setGear(int newGear)
newGear
- is the gear to set to.public java.lang.String toString()
toString
in class java.lang.Object
public int compareTo(Car otherCar)
compareTo
in interface java.lang.Comparable<Car>
otherCar
- is the car to which to compare