import java.util.*
//这里不能用car ,重新起一个名字,因为和下面的class Car冲突了。
public class test {
private static Scanner input
public static void main(String args[]){
input = new Scanner(System.in)
System.out.println("请输入车主姓名,车速,方向盘角度")
Car car=new Car(input.next(),input.nextFloat(),input.nextFloat())
System.out.println("车主姓名为:"+car.getOwnerName())
System.out.println("当前车速为:"+car.getCurSpeed())
System.out.println("当前方向盘角度为:"+car.getCurDirInDegree())
System.out.println("修改车速")
System.out.println("新的车速为:")
car.changeSpeed(input.nextFloat())
System.out.println("在调用changeSpeed(80)后,车速为"+car.getCurSpeed())
car.stop()
System.out.println("在调用stop()后,车速为"+car.getCurSpeed())
}
}
class Car {
private String ownerName//车主姓名
private float curSpeed//当前车速
private float curDirInDegree//当前方向盘转向角度
public Car (String ownerName){
this.ownerName=ownerName
}
public Car (String ownerName, float speed, float dirInDegree){
this(ownerName)
curSpeed=speed
curDirInDegree=dirInDegree
}
public String getOwnerName() { //提供对车主姓名的访问
return ownerName
}
public float getCurDirInDegree() { //提供对当前方向盘转向角度的访问
return curDirInDegree
}
public float getCurSpeed() { //提供对当前车速的访问
return curSpeed
}
public void changeSpeed(float curSpeed) { //提供改变当前的车速
this.curSpeed=curSpeed
}
public void stop(){ //提供停车
curSpeed = 0
}
}
请采纳答案,支持我一下。