Having trouble with calculations... what's wrong?

Having trouble calculating this out. The rest of the coding is fine but this one class. The error focuses on one line.

  • retail_price = double.parseDouble(input1) * (double.parseDouble(input2) / 100);

The errors tell me that "class expected" "; expected" and "not a statement". Where am I going wrong because this seems correct to me?

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 );
    }
Jon Skeet
people
quotationmark

The name of the class containing parseDouble is Double, not double. They are not synonyms. double is the name of the primitive type, and primitives do not have methods.

So you need:

retail_price = Double.parseDouble(input1) * (Double.parseDouble(input2) / 100);

However, you should also strongly consider using BigDecimal instead of Double anyway, as that's a better match for currency values.

Additionally, I'd recommend:

  • Following Java naming conventions, using camelCase instead of underscore separators
  • Giving your variables more meaningful names - what are input1 and input2 meant to represent? A price and a discount, perhaps?
  • Declaring variables only where you need to, rather than at the start of the method
  • Considering what you want to happen if the value entered by the user isn't a valid number
  • Considering whether you care about internationalization (e.g. a user entering "10,50" instead of "10.50". If so, look at NumberFormat and DecimalFormat

people

See more on this question at Stackoverflow