All pastes #1593734 Raw Edit

Car

public java v1 · immutable
#1593734 ·published 2009-10-05 04:15 UTC
rendered paste body
/** * A class which constructs a Car with a certain fuel efficiency in miles per gallon. */public class Car{    /**     * Constructs a car with a specified fuel efficiency.     * @param fuelEfficiency The amount of miles able to be traveled per gallon.     */    public Car(int fuelEfficiency)    {        efficiency = fuelEfficiency;    }       /**     * Adds gas to the car's tank.     * @param addGas The amount of gas in gallons to add to the car's tank.     */    public void addGas(double addGas)    {        gas = gas+addGas;    }    /**     * Drive the car and subtract the appropriate amount of gas as specified by the car's efficiency.     * @param milesToDrive The distance in miles to drive the car.     */    public void drive(double milesToDrive)    {        gas =  gas - (milesToDrive / efficiency);    }    /**     * Returns the current amount of gas in gallons left in the tank.     */    public double getGasInTank()    {        return gas;    }        private double efficiency;    private double gas;}