car2.java

来自「java2 primer plus一书源程序」· Java 代码 · 共 72 行

JAVA
72
字号
public abstract class Car2 
{
    // Transmission types
    public static final int AUTOMATIC = 0;
    public static final int TIPTRONIC = 1;
    public static final int MANUAL = 2;

    // Attributes
    protected String typeOfCar2;
    protected int horsePower;
    protected int maximumSpeed;
    protected int numberOfDoors;
    protected String paint;
    protected int gasCapacity;
    protected int oilCapacity;
    protected int transmission;

    // State attributes
    protected boolean running = false;
    protected int currentSpeed;
    protected int currentGas;
    protected int currentOil;

    public Car2( String typeOfCar2,
                int horsePower,
                int maximumSpeed,
                int numberOfDoors,
                String paint,
                int gasCapacity,
                int oilCapacity,
                int transmission )
    {
        this.typeOfCar2 = typeOfCar2;
        this.horsePower = horsePower;
        this.maximumSpeed = maximumSpeed;
        this.numberOfDoors = numberOfDoors;
        this.paint = paint;
        this.gasCapacity = gasCapacity;
        this.oilCapacity = oilCapacity;
        this.transmission = transmission;
    }

    public void start()
    {
        running = true;
    }

    public void stop()
    {
        running = false;
    }

    public boolean isRunning()
    {
        return running;
    }

    public abstract void accelerate();

    public abstract void decelerate();

    public int getCurrentSpeed()
    {
        return currentSpeed;
    }

    public String toString()
    {
        return typeOfCar2; 
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?