方法:移动(move())、设置速度(jetspeed(int speed)、加速(speedUp())、减速(speedDown())等。
类:
package tt;
public class Vehicle {
int speed,size;
public Vehicle(int a,int b)
{
speed=a;
size=b;
}
public Vehicle()
{
}
public void setSpeed(int speed)
{
System.out.println("速度"+speed);
//return speed;
}
public void setSize(int size)
{
System.out.println("体积"+size);
//return size;
}
public void speedUp()
{
speed=speed+20;
System.out.println("加速后"+speed);
}
public void speedDown()
{
speed=speed-10;
System.out.println("减速后"+speed);
}
public void move()
{
System.out.println("移动");
}
}
测试类:
package tt;
import java.util.Scanner;
public class Vehiclecs {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);//输入
System.out.println("请输入速度");
int a=input.nextInt();
System.out.println("请输入体积");
int b=input.nextInt();
Vehicle vehicle=new Vehicle(a,b);
vehicle.setSpeed(a);
vehicle.setSize(b);
vehicle.move();
vehicle.speedUp();
vehicle.speedDown();
}
}
测试结果: