📄 newcar.java
字号:
public abstract class NewCar
{
// Transmission types
public static final int AUTOMATIC = 0;
public static final int TIPTRONIC = 1;
public static final int MANUAL = 2;
// Attributes
protected String typeOfCar;
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 NewCar( String typeOfCar,
int horsePower,
int maximumSpeed,
int numberOfDoors,
String paint,
int gasCapacity,
int oilCapacity,
int transmission )
{
this.typeOfCar = typeOfCar;
this.horsePower = horsePower;
this.maximumSpeed = maximumSpeed;
this.numberOfDoors = numberOfDoors;
this.paint = paint;
this.gasCapacity = gasCapacity;
this.oilCapacity = oilCapacity;
this.transmission = transmission;
}
public void start() throws CarException
{
if( this.running == true )
{
CarException e = new CarException( "Car is already running --- nasty grinding noise!" );
e.setEngineRunning( true );
throw e;
}
running = true;
}
public void stop() throws CarException
{
if( this.running == false )
{
CarException e = new CarException( "Car is not running!" );
e.setEngineRunning( false );
throw e;
}
running = false;
}
public boolean isRunning()
{
return running;
}
public abstract void accelerate() throws CarException;
public abstract void decelerate() throws CarException;
public abstract void tuneUp();
public abstract void changeOil();
public int getCurrentSpeed()
{
return currentSpeed;
}
public String toString()
{
return typeOfCar;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -