gpt4 book ai didi

Java-错误 :cannot find symbol

转载 作者:行者123 更新时间:2023-12-01 23:53:07 25 4
gpt4 key购买 nike

我正在编写一个程序,该程序从同一文件夹中的不同类调用“发票”方法。我不断收到以下错误:

error: cannot find symbol

strInvoice = invoice();
^
symbol: method invoice()

以下是我在程序中调用该方法的方式:

strInvoice= invoice();
JOptionPane.showInputDialog(null, strInvoice, "*Name*'s Party Store", -1);

这是位于同一文件夹中的类文件中的方法的样子:

public String invoice()
{
String strInfo=""; //string returned containing all the information
double dBalloonNoDiscount; //balloon total without discount
double dCandleNoDiscount; //candle total without discount
double dBannerNoDiscount; //banner total without discount
double dSubtotal; //subtotal
double dTax; //tax
double dShippingCost; //shipping cost
double dTotal; //total
String strShippingType; //shipping type

dBalloonNoDiscount = balloons * 2.50;
dCandleNoDiscount = candles * 6.00;
dBannerNoDiscount = banners * 2.00;

dSubtotal = subtotal();
dTax = tax();
dShippingCost = shippingCost();
strShippingType = shippingType();
dTotal = orderTotal();

strInfo += "\nQuantity"
+ "\n\nBalloons: " + balloons + " @ $2.50 = "
+ df.format(dBalloonNoDiscount) + "* Discount Rate: "
+ df.format(discount('B')) + " = "
+ df.format(subtotal('B'))
+ "\n\nCandles: " + candles + " @ 6.00 = "
+ df.format(dCandleNoDiscount) + "* Discount Rate: "
+ df.format(discount('C')) + " = "
+ df.format(subtotal('C'))
+ "\n\nBanners: " + banners + " @ $2.50 = "
+ df.format(dBannerNoDiscount) + "* Discount Rate: "
+ df.format(discount('N')) + " = "
+ df.format(subtotal('N'))
+ "\nSubtotal: " + df.format(dSubtotal)
+ "\n Tax: " + df.format(dTax)
+ "\nShipping: " + df.format(dShippingCost) + " - "
+ strShippingType
+ "\n Total: " + dTotal;

return strInfo;
}

我希望这是足够的信息。我只是似乎找不到问题所在。

最佳答案

I am writing a program that calls upon the "invoice" method from a different 
class in the same folder.

然后你这样调用它:

strInvoice= invoice();

这不起作用,因为您需要将此方法调用为:

strInvoice = obj.invoice();

其中 obj 是另一个类的实例。

或者,如果invoice()方法是public static,那么您也可以这样调用它:

strInvoice = SomeClass.invoice();

关于Java-错误 :cannot find symbol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16067098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com