📄 pinto.java
字号:
public class Pinto extends Car
{
// State attributes
public boolean hatchBackDoorOpen = false;
public Pinto()
{
super( "Pinto",
50,
60,
5,
"two-tone",
15,
5,
Car.MANUAL );
}
public void accelerate()
{
// Check to see if we are running or not
if( running == false )
{
return;
}
currentSpeed += 4;
if( currentSpeed > maximumSpeed )
{
currentSpeed = maximumSpeed;
// The high speed knocked the door open!
openHatchBack();
}
}
public void decelerate()
{
currentSpeed -= 5;
if( currentSpeed < 0 ) currentSpeed = 0;
}
public void tuneUp()
{
System.out.println( "Tuning up a pinto..." );
}
public void changeOil()
{
System.out.println( "Changing a pinto's oil..." );
}
public void rollStart()
{
running = true;
}
public void pushUpHill()
{
System.out.println( "Ouch, this thing is heavy!" );
}
public void openHatchBack()
{
hatchBackDoorOpen = true;
}
public void closeHatchBack()
{
hatchBackDoorOpen = false;
}
public boolean isHatchBackDoorOpen()
{
return hatchBackDoorOpen;
}
public static void main( String[] args )
{
Pinto p = new Pinto();
System.out.println( "My car: " + p );
p.start();
if( p.isRunning() == false )
{
System.out.println( "Starter failed, let's roll start it!" );
p.rollStart();
}
System.out.println( "Current speed: " + p.getCurrentSpeed() +
", Hatchback open = " + p.isHatchBackDoorOpen() );
for( int i=0; i<20; i++ )
{
p.accelerate();
System.out.println( "Current speed: " + p.getCurrentSpeed() +
", Hatchback open = " + p.isHatchBackDoorOpen() );
}
while( p.getCurrentSpeed() > 0 )
{
p.decelerate();
System.out.println( "Current speed: " + p.getCurrentSpeed() +
", Hatchback open = " + p.isHatchBackDoorOpen() );
}
p.stop();
if( p.isHatchBackDoorOpen() )
{
System.out.println( "Have to close the hatchback!" );
p.closeHatchBack();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -