這個小方法是一個包含許多獨立類的非常大的程序的一部分。下面的方法是打電話給我的購買類的一部分,該類跟蹤購買了多少庫存。不過,雖然我已經實例如下上述調用另一個類的單獨類的方法
Purchase currentPurchase;
我繼續秉承「標識有望」的錯誤,「找不到符號」。
方法:
public double processPurchase(currentPurchase){
lemonsBought = currentPurchase.getNumLemonsBought();
iceBought = currentPurchase.getNumLemonsBought();
cupsBought = currentPurchase.getNumCupsBought();
sugarBought = currentPurchase.getNumSugarBought();
lemonInventory += lemonsBought;
iceInventory += iceBought;
cupInventory += cupsBought;
sugarInventory += sugarBought;
money -= (.5 * lemonsBought) + (2 * iceBought) + (2 * cupsBought) + (0.25 * sugarBought);
return currentPurchase;
}
金錢是一個獨立的預實例變量
你在哪裏放行「Purchase currentPurchase;」? 「currentPurchase」是您購買類的一個字段嗎?如果是這樣,則不需要再次將其指定爲實例方法「processPurchase」的參數。 – dacongy