无法计算出来。其余的编码很好但是这一类。错误集中在一行。
错误告诉我“课程预期”,“预期”和“不是声明”。我哪里出错了,因为这对我来说似乎是正确的?
private class CalcButtonListener implements ActionListener
{
// The actionPerformed method executes when the user clicks the calculate button
public void actionPerformed(ActionEvent e)
{
double retail_price;
String input1;
String input2;
//Get the number from the users input in priceFeild1
input1 = priceField1.getText();
//Get the number from the users input in priceFeild2
input2 = priceField2.getText();
// Calculate out the operation below to find the retail_price
retail_price = double.parseDouble(input1) * (double.parseDouble(input2) / 100);
JOptionPane.showMessageDialog(null, "The retail price of the item is: $" + retail_price );
}
答案 0 :(得分:3)
包含parseDouble
的类的名称是Double
,而不是double
。它们是不是的同义词。 double
是基元类型的名称,基元没有方法。
所以你需要:
retail_price = Double.parseDouble(input1) * (Double.parseDouble(input2) / 100);
但是,您还应强烈考虑使用BigDecimal
而不是Double
,因为这是货币值的更好匹配。
另外,我建议:
camelCase
而不是下划线分隔符input1
和input2
代表什么?可能是价格还是折扣?NumberFormat
和DecimalFormat
答案 1 :(得分:1)
尝试:
Double.parseDouble(input1)
答案 2 :(得分:1)
解析双retail_price = Double.parseDouble(input1) * (Double.parseDouble(input2) / 100);