[英]Calling a method of a seperate class into another class
This small method is part of a very large program with many separate classes. 这个小方法是一个包含许多单独类的非常大的程序的一部分。 The method below is meant to call in a portion of my Purchase class which keeps track of how much inventory is bought.
下面的方法是为了调用我的Purchase类的一部分来跟踪购买的库存量。 However, although I have instantiated as follows above
但是,虽然我已经实例化如下
Purchase currentPurchase;
I continue to receive the errors "identifier is expected", and "cannot find symbol". 我继续收到错误“标识符是预期的”,“无法找到符号”。
Method: 方法:
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;
}
Money is a separate pre-instantiated variable Money是一个单独的预先实例化的变量
您需要将标识符添加到您的函数中,否则java编译器将不知道它应该接收什么。
public double processPurchase(Purchase currentPurchase){
我认为你正在返回一个错误的变量currentPurchase,你已经将其作为一个参数传递而我甚至没有操纵它。你确定你需要这个变量或者钱也是一个双变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.