请定义一个交通工具(Vehicle)的类其中有:属性速度(speed)体积(size)等等方法移动(move())设置速度(setSpeed(int speed))加速speedUp(),减速speedDown()等等,最后在测试类Vehicle中main()中实例化一个交通工具对象并通过方法给它初始化speed,size的值并且通过打印出来。另外调用加速减速的方法对速度进行改变。
public class Vehicle{ private int speed; private String size; public void move(){ System.out.println("i'm moving"); } public void setSpeed(int speed){ System.out.println("now i'm runing with"+speed+"per hour"); } public void speedUp(){ Vehicle v=new Vehicle(); v.setSpeed(1000); } public void speedDown(){ Vehicle v=new Vehicle(); v.setSpeed(20); } public static void main(String[] grg){ Vehicle v=new Vehicle(); v.speed=100; v.size="50/m^3"; System.out.println("the initial speed is"+v.speed+"and my size is"+v.size); v.speedUp(); v.speedDown(); } }