-2
我被困在一個練習中,這真的讓我難以忍受。基本上在這個代碼中,我希望這個傳遞方法的結果調用increaseQuantity
方法,雖然我相信它很簡單,但編譯時我經常遇到一個錯誤。增加數量錯誤 - 解決方案?
錯誤消息讀取:類產品
方法increaseQuantity不能給予給定的類型;需要int;發現:沒有參數;理由:實際和正式參數列表的長度不同。
我已經從字面上撞上了這面牆,所以任何幫助將不勝感激十倍!
public int delivery (int id, int amount)
{
int index = 0;
boolean searching = true;
Product myproduct = stock.get(0);
while(searching && index < myproduct.getID()){
int Products = myproduct.getID();
if(Products == id) {
searching = false;
}
else {
index++;
}
}
if(searching) {
return 0;
}
else {
return myproduct.increaseQuantity();
}
}
非常感謝那些迴應。
好吧,你需要添加一個'int'參數,如錯誤 – AxelH
看起來你'increaseQuantity()'方法需要一個'int'作爲參數,但你給它什麼都不說。此外,如果您在編程時「實際上」撞牆,您需要與工作場所的健康和安全代表聯繫。 – jsheeran
也許你可以分享你的產品類代碼,或者至少增加incrementQuantity()方法的源代碼 – alainlompo