|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcar.Car
public class Car
Class invariants:
Field Summary | |
---|---|
static int |
FORWARD
|
static int |
PARK
|
static int |
REVERSE
|
Constructor Summary | |
---|---|
Car()
Create a car that gets 20 mpg and has a tank capacity of 10 gallons |
Method Summary | |
---|---|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int PARK
public static final int FORWARD
public static final int REVERSE
Constructor Detail |
---|
public Car()
Method Detail |
---|
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 = max(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
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |