对不起初学者编码器,我不擅长解释事情,但得到这个错误代码,指出:二元运算符'+'的错误操作数类型,第一种类型: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如果任何人都可以帮助我编码,这将不胜感激。 如果您需要更多信息,请告诉我。 先谢谢你。
Hi sorry beginner coder here and I am not good at explaining things very well but have been getting this error code that states: bad operand types for binary operator '+', first type: int; second type:java.util.ArrayList. Then it highlights the totalIC = totalIC + l.getInventory(); part below. I am not sure how to fix this issue, also I am also using BlueJ compiler. Here is my code that I am having issues with:
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; }Here is where I am getting my l.getInventory(); from:
public ArrayList<Lamborghini> getInventory() { return inventory; }These are the methods I am suppose to be using:
public int getTotalInventoryCount()
Using a foreach loop, gets the total inventory of car lots Returns 0 if carLots ArrayList is nullIf anyone can help me with coding this that would be greatly appreciated. If you need more information please let me know. Thank you in advance.
最满意答案
您无法将ArrayList添加到int。
totalIC = totalIC + l.getInventory(); ^ ^ ^ int int ArrayList containing Lamborghini-Objects我假设你想知道清单中包含多少兰博基尼物体。
要这样做,你会打电话
l.getInventory().size();You can not add an ArrayList to an int.
totalIC = totalIC + l.getInventory(); ^ ^ ^ int int ArrayList containing Lamborghini-ObjectsI assume you want to know how many Lamborghini-Objects are contained in the inventory.
To do so, you would call
l.getInventory().size();更多推荐
发布评论