1.

XYZ Pens Company sells each pen at the cost of < 25.00. The programmer has developed a GUI application as shown below:(i) The number of pens bought are entered by the user.(ii) The Amount is Number of Pens * 25.00(iii) If a person buying pens is a 'Special Customer', a discount of 5% is given on the amount, otherwise no discount is given.(iv) Amount to be paid = Amount - DiscountWrite code in Java to do the following:(i) When Calculate button is clicked the Amount, Discount and Amount to be Paid are calculated and should be displayed in appropriate text fields.(ii) When Clear button is clicked, all the Textfields and Checkbox are cleared.(iii) When Stop button is clicked, the application is closed.

Answer»

(i) float amt, discount = 0.0;

int n = Integer.parselnt(TextNoofpens.getText());

amt = n * 25;

If (jSpeicalCustomer.isSelected() = = True)

{

discount = amt + 0.05;

amt = amt - discount;

}

jTextDiscount.setText(discount.toString());

jAmount.setText(amt.toString());

(ii) jNoofpens.setText(" ");

jTextDiscount.setText(" ");

jAmount.setText(" ");

jSpecialCustomer.setSelected(False);

(iii) System.exit(0);



Discussion

No Comment Found