Search code examples
javaif-statementillegalstateexception

if "illegal start of expression"


I am making a discount GUI for my computer science class. We are to "Create an application that prompts the user for the amount of purchases and then returns the discounted price."

I have created my program but I keep getting the illegal start of expression error.

private void CalculateDiscountActionPerformed(java.awt.event.ActionEvent evt) {                                                  
    // declaring variables
    double dblInitialPrice;
    double dblDiscount;
    double dblTotalPrice;
    double dblTotal;

    DecimalFormat Formatter = new DecimalFormat("###.00");

    // assigning values to variables
    dblInitialPrice = Double.parseDouble(AmountOfPurchases.getText());
    dblDiscount = dblInitialPrice * (0.10);
    dblTotalPrice = dblInitialPrice - dblDiscount;
    dblTotal =  
    if (dblInitialPrice >= 10)  { // error here "illegal start of expression" for if
        DiscountPrice.setText("" + Formatter.format(dblDiscount) + "$");
        DiscountAmount.setText("" + Formatter.format(dblTotalPrice) + "$");
    } else if (dblInitialPrice <= 10){
        DiscountPrice.setText("0.00$");
        DiscountAmount.setText("" + dblInitialPrice + "$");
    }

Solution

  • dblTotal = is not a complete expression. You need something on the right-hand side.