Having trouble calculating this out. The rest of the coding is fine but this one class. The error focuses on one line.
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 );
}
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:
camelCase
instead of underscore separatorsinput1
and input2
meant to represent? A price and a discount, perhaps?NumberFormat
and DecimalFormat
See more on this question at Stackoverflow