如何修复我的getTotalInventoryCount()?(How to fix my getTotalInventoryCount()? bad operand types for binary

编程入门 行业动态 更新时间:2024-10-27 05:35:27
如何修复我的getTotalInventoryCount()?(How to fix my getTotalInventoryCount()? bad operand types for binary operator?)

对不起初学者编码器,我不擅长解释事情,但得到这个错误代码,指出:二元运算符'+'的错误操作数类型,第一种类型: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 null

If 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-Objects

I assume you want to know how many Lamborghini-Objects are contained in the inventory.

To do so, you would call

l.getInventory().size();

更多推荐

本文发布于:2023-07-26 19:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1280253.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:bad   fix   getTotalInventoryCount   operand   operator

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!