public CarDealerShip() {
cars = new Car[80];
listSize=0;
}
public void addNewCar (String model, int year, int price, String color) {
m = model;
y = year;
p = price;
c = color;
cars [listSize] = new NewCar (m,y,p,c);
listSize++;
}
public void addUsedCar (String model, int year, int price, boolean rusty) {
m = model;
y = year;
p = price;
r = rusty;
cars [listSize] = new UsedCar(m,y,p,r);
listSize++;
}
public String printReport() {
String list="";
if (cars.length==listSize)
for (int i =0; i <= listSize; i++)
list+=cars[i].toString()+"\n";
return list;
}
printReport
の方法では、forループは変数リストを更新することを想定していますが、まったく何もしません。私はもう一度Javaを使用しているので、しばらくお待ちしております。java forループで変数が更新されない
StackOverflow! downvoteは、説明を伴ってより建設的に作られています。 –
(cars.length == listSize -1)は問題を解決する可能性があります。 –
@aa_oo 'cars = new Car [80]'と宣言された場合、 'cars.length'は常に' 80'と等しくないでしょうか? –