当汽车离开时,汽车在车库内移动的次数应与车牌一起显示。我目前得到的输出显示一切正常,但所有汽车的移动次数保持为 0。我无法确定如何增加变量并在输出中显示累积值。我该如何解决?
汽车类
package garagetester;
public class Car
{
private String licensePlate;//stores the license plate of the car as a String
private int movesCount = 0;//stores the number of times the car has been
//moved
public Car(String licensePlate)//builds a Car object with
{
this.licensePlate = licensePlate;
}
public String getLicensePlate() {
return licensePlate;
}
public int getMovesCount() {
return movesCount;
}
public void incrementMovesCount(int movesCount) {
movesCount++;
}
}//end of Car class
临摹微笑
相关分类