vendredi 2 octobre 2015

What if both the Checkboxes are selected?

In this program i'm not able to fulfill the 3rd else if condition that is when both the check-boxes are selected.It is still displaying 40% of the price whereas it should display 50%.

int p=Integer.parseInt(jTextField1.getText()); //Product Price
        int dis=40*p/100; //40% discount
        int adis=10*p/100; //10% discount
        int tdis=50*p/100; //50% discount
        int fpd=p-dis; // final price (40% discount)
        int fpad=p-adis; //final price (10% discount)
        int fptdis=p-tdis;// final price (50% discount)

        if (jCheckBox1.isSelected()==true)
            jLabel3.setText("dis is 40% "+"dis amt is "+dis+"final price is "+fpd);
        else if (jCheckBox2.isSelected()==true)
            jLabel3.setText("dis is 10% "+"dis amt is "+adis+"final price is "+fpad);
    // This condition is not working!!
        else if (jCheckBox1.isSelected()==true && jCheckBox2.isSelected()==true)
            jLabel3.setText("dis is 50% "+"dis amt is "+tdis+"final price is "+fptdis);
        else jLabel3.setText("no discount"+"final price is "+p);

Aucun commentaire:

Enregistrer un commentaire