您好抱歉初学编码器在这里,我不擅长解释事情,但已经得到这个错误代码,声明:二元运算符的错误操作数类型'',第一种类型:int;第二种类型:java.util.ArrayList . 然后它突出显示totalIC = totalIC l.getInventory();部分如下 . 我不知道如何解决这个问题,我也在使用BlueJ编译器 . 以下是我遇到问题的代码:
public int getTotalInventoryCount()
{
int totalIC = 0;
int cars = 0;
for(LamborghiniCarLot l : carLots){
if(l.getInventory().equals(getCarLots())){
totalIC = totalIC + l.getInventory();
cars++;
}
}
return cars;
}
这是我得到我的l.getInventory();从:
public ArrayList<Lamborghini> getInventory()
{
return inventory;
}
这些是我想要使用的方法:
public int getTotalInventoryCount()
-
使用foreach循环获取汽车批次的总库存
-
如果carLots ArrayList为null,则返回0
如果有人可以帮我编码,那将非常感激 . 如果您需要更多信息,请告诉我 . 先感谢您 .
1 回答
您不能将ArrayList添加到int .
我假设您想知道库存中包含多少兰博基尼物体 .
要这样做,你会打电话