谁能帮我。我想通过一种方法比较两辆车是否更快isFaster(Car otherCar)
。有人可以帮助我了解如何将Car
对象与作为方法otherCar
参数的对象进行比较isFaster
。我怎样才能开始创建方法的主体。
public class Car {
private String make ="";
private int year = 0;
private int maxSpeed = 0;
public Car(String make,int year,int maxSpeed){
this.make = make;
this.maxSpeed = maxSpeed;
this.year = year;
}
public void setSpeed(int maxSpeed){
this.maxSpeed = maxSpeed;
}
public void setMake(String make){
this.make = make;
}
public void setYear(int year){
this.year = year;
}
public int getMaxSpeed(){
return maxSpeed;
}
public int getYear(){
return year;
}
public String getMake(){
return make;
}
public String toString(double param){
String temp = String.valueOf(param);
return temp;
}
public String toString(int param){
String temp = String.valueOf(param);
return temp;
}
public String toString(char param){
String temp = String.valueOf(param);
return temp;
}
}