请问以下错误出现的原因
出现了 错误: 此处不允许使用 '空' 类型
减速speedDown()
public void speedDown(int speed){
System.out.println("减速到:"+getSpeed(setSpeed(getSpeed()-speed)));
}
代码相关问题:请定义一个交通工具(Vehicle)的类
其中有属性:
速度(speed)
体积(size)等等
方法移动(move())
设置速度(setSpeed(int speed))
加速speedUp(),
减速speedDown()等等.
public class Homework2
{
public static void main(String[] args){
Vehicle v1=new Vehicle(17.3,20.0);
v1.setSpeed(10);
v1.speedDown(20);
}
}
class Vehicle
{
//属性
//速度
private double speed;
//体积
private double size;
//构造方法
public Vehicle(){
this(0.0,0.0);
}
public Vehicle(double speed,double size){
this.speed=speed;
this.size=size;
}
public void setSpeed(double speed){
this.speed=speed;
}
public double getSpeed(){
return this.speed;
}
public void setSize(double size){
this.size=size;
}
public double getSize(){
return this.size;
}
//move()
public void move(){
System.out.println("移动了");
}
//设置速度setSpeed(int speed)
public void setSpeed(int speed){
setSpeed(getSpeed()+speed);
}
//加速speedUp(),
public void speedUp(int speed){
setSpeed(getSpeed()+speed);
System.out.println("加速到:"+getSpeed());
}
public void speedDown(int speed){
setSpeed(getSpeed()-speed);
System.out.println("减速到:"+getSpeed());
}
/*
是错误的,不明白错误
出现了 错误: 此处不允许使用 '空' 类型
减速speedDown()
public void speedDown(int speed){
System.out.println("减速到:"+getSpeed(setSpeed(getSpeed()-speed)));
}
*/
}