Design Solution

Q1  Garments has developed a GUI application for their company as shown below :



The company accepts payments in 3 modes- cheque , cash and credit cards. The discount given as per mode of payment is as follows.
Mode of Payment  
Discount
Cash
8%
Cheque 
7%
Credit Card  
Nil
If the Bill Amount is more than 15000 then the customer gets an additional discount of 10% on Bill
Amount
 (1) Make Discount and Net amount uneditable.
(2) Write codes for calculate Discount and calculate Net Amount Buttons
(3) Write code to exit program when STOP button is clicked.
Solution:
//Code for calculate button
 txtDiscount.setEditable(false);
 txtNetAmt.setEditable(false);
 String name= txtname.getText();
double bm=Double.parseDouble(txtbillamt.getText(););
double disc=0.0, netAmt=0.0;
String s= cmbMode.getSelectedItem();
 if(s.equals(“Cash”)) { disc= 0.08*bm; }
 else if(s.equals(“Cheque”)) { disc=0.07*bm; }
 else if(s.equals(“Cash”)) { disc=0; }
netAmt=bm-disc;
txtDiscount.setText(“ “+disc);
txtNetAmt.setText(“ “+netAmt);

//code for stop button
System.exit(0);

Q2  A programmer is required to develop a student record. The school offers two different streams, medical and non-medical, with different grading criteria.The following is the data entry screen used to calculate percentage and grade.

(1)Write the code to disable the txtPercentage and the txtGrade text fields.
(2) Write the code for the cmdClear button to clear all the text fields.
(3) Write the code for the cmdCalcPerc button to calculate the percentage to display in text field txtPercentage, after
finding the total marks of first term and second term (assuming that both marks are out of 100).
(4) Write the code for the cmdCalcGrade button to calculate the grade to display in text field txtGrade, depending on the stream selected according to the criteria in the following table:

Solution:
// code for calculate percentage
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
double f = Double.parseDouble(ftf.getText());
double s = Double.parseDouble(stf.getText());
double per = (f + s)/ 2 ;
pertf.setText("" + per);
jButton2.setEnabled(true);
}
//code for calculate grade
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{
double p = Double.parseDouble(pertf.getText());
String gr = "" ;
if(medrb.isSelected())
{
if(p>=80)
{
gr = "A";
}
else if(p >= 60 && p <= 80)
{
gr = "B";
}
else if(p<=80)
{
gr = "C";
}
}
else if(nonrb.isSelected())
{
if(p>=75)
{
gr = "A";
}
else if(p >= 50 && p <= 75)
{
gr = "B";
}
else if(p<=50)
{
gr = "C";
}
}
gratf.setText("" + gr);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)
{
ftf.setText("");
stf.setText("");
pertf.setText("");
gratf.setText("");
}


Q3. An Election is conducted between 3 candidates. There are N number of voters. By clicking Next Voter Button textboxes and RadioButtons need to be cleared. By clicking Results, the votes obtained by each candidate and the winner candidate to be displayed in text area. Exit button should exit program.

Solution:
// type inside the class
int vote1 ;
int vote2 ;
int vote3 ;
//code for next Voter Button
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
nametf.setText("");
frb.setSelected(false);
srb.setSelected(false);
trb.setSelected(false);
resta.setText("");
}
//Code for Result Button
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
resta.setText("");
resta.append("Candidate 1 = " + vote1 + "\n");
resta.append("Candidate 2 = " + vote2 + "\n");
resta.append("Candidate 3 = " + vote3 + "\n");
if(vote1>vote2 && vote1 > vote3)
{
resta.append("Winner is Candidate 1");
}
else if(vote2>vote1 && vote2 > vote3)
{
resta.append("Winner is Candidate 2");
}
else if(vote3>vote1 && vote3 > vote2)
{
resta.append("Winner is Candidate 3");
}
if(vote1==vote2 && vote1==vote3)
{
resta.append("The Election is draw");
}
}
private void frbMousePressed(java.awt.event.MouseEvent evt)
{
vote1++ ;
}
private void srbMousePressed(java.awt.event.MouseEvent evt)
{
vote2++ ;
}
private void trbMousePressed(java.awt.event.MouseEvent evt)
{
vote3++ ;
}
//code for stop button
System.exit(0);

Q4. Develop an application to accept a String and perform following functions :-
  
(    (1)    find length of the string 
     (2) find no of words in it
    (3) find string is palindrome or not 
    (4) find number of vowels in it. All output to be displayed using JOptionPane.




 
 

Solution:
on find length button:-
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String str = strtf.getText();
JOptionPane.showMessageDialog(rootPane, "Length = " + str.length());
}
on find word button:-
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
String str = strtf.getText();
int s = 1 ;
for(int i = 0;i<str.length();i++)
{
if(str.charAt(i) == ' ')
{
s++ ;
}
}
JOptionPane.showMessageDialog(rootPane, "N.of word = " + s);
}
on find Vowel button:-
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
String str = strtf.getText();
int i ;
int vowel = 0;
for(i = 0; i<str.length(); i++)
{
switch(str.charAt(i))
{
case 'A' :
case 'E' :
case 'I' :
case 'O' :
case 'U' :
case 'a' :
case 'e' :
case 'i' :
case 'o' :
case 'u' : vowel++ ;
}
}
JOptionPane.showMessageDialog(rootPane, "N.of vowels are = " + vowel);
}
on palindrome button:-
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
String str = strtf.getText();
int i = 0; int j = str.length()-1;
int flag = 0 ;
while(i < str.length()/2)
{
if(str.charAt(i)!= str.charAt(j))
{
flag = 1 ;
break;
}
else
{
i++;
j--;
}
}
if(flag ==1)
{
JOptionPane.showMessageDialog(rootPane, "It is not a palindrome");
}
else
{
JOptionPane.showMessageDialog(rootPane, "It is a palindrome");
}
}


Q5. ABN Shipment Corporation imposes charges to customers for different product .The shipment company costs for an order in two forms: Wholesalers and Retailers . The cost is calculated on unit basis as follows:

For units

Price for wholesalers(per unit)
Price for retailers(per unit)
1-15
16-20
21-30
31-50
>50
Rs.50/-
Rs.45/-
Rs.40
Rs.35/-
 Rs.30/-
Rs.60/-
 Rs.55/-
Rs.50/-
Rs.45/-
Rs.40/-
1) Write the code to disable the text boxes txtTCost and Wholesaler as default option when the form isactive.
(2) Write the code for Calculate Cost command button(cmdCalc) to
(i) Display the discount price in txtDisc if special customer is selected. Discount is at the rate of 10%
of Total cost.
(ii) To display total cost.(Total cost = Ordered Unit * Unit Price-Discount Price)
(3) Write the code for Exit Button (cmdExit) to exit the application.
Solution:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
disctf.setText("0");
int unit = Integer.parseInt(unittf.getText());
int p = 0; double d = 0 ;
if(wrb.isSelected())
{
if(unit >= 1 && unit <= 15)
{
p = unit * 50 ;
}
else if(unit >= 16 && unit <= 20)
{
p = unit * 45 ;
}
else if(unit >= 21 && unit <= 30)
{
p = unit * 40 ;
}
else if(unit >= 31 && unit <= 50)
{
p = unit * 35 ;
}
else if(unit > 50 )
{
p = unit * 30 ;
}
}
else if(rrb.isSelected())
{
if(unit >= 1 && unit <= 15)
{
p = unit * 60 ;
}
else if(unit >= 16 && unit <= 20)
{
p = unit * 55 ;
}
else if(unit >= 21 && unit <= 30)
{
p = unit * 50 ;
}
else if(unit >= 31 && unit <= 50)
{
p = unit * 45 ;
}
else if(unit > 50 )
{
p = unit * 40 ;
}
}
tctf.setText("" + p);
if(schk.isSelected())
{
double t = Double.parseDouble(tctf.getText());
d = t * 0.10 ;
disctf.setText("" + d);
double sp = t - d ;
tctf.setText("" + sp);
}
}

Q6. NDPL generates computerized bills for its customers on every month the bill is generated for four Consumption as follows.


Consumption Section
1 st 200 Units (Rs./Unit)
Next 200 Units (Rs./Unit)
Above 400 Units (Rs./Unit)
Domestic Light 
2.45
3.95
4.65
Non Domestic Light Up to 10KW
5.40
5.40
5.40
Non Domestic Light Above 10KW
4.92
 4.92
4.92
Agricultural Power Up to 10KW

1.55
1.55
Agricultural Power Above 10KW 
9.84
9.84
9.84
Industrial Power Up to 10KW
5.05
5.05
5.05
Industrial Power Up to 10KW
4.40
4.40
4.40

(i) Create a Java Desktop application using Swing controls to read the number of units consumed and
print out the charges. Design the IDE by taking Consumption Sections into JradioButtons and the Up
to 10KW and above 10KW in JCheckBox controls. Bill need to be displayed using JOptionPane.
While coding do the following also:
·         When you click on Domestic Light button, disable the Up to 10KW and Above 10KW buttons
·         When you click on other three buttons except Domestic Light in Consumption Section, both JCheckBox control will be set to enabled.
(ii) Write the code for Exit button to exit the application.
Solution:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int unit = Integer.parseInt(unittf.getText());
double charge = 0 ;
if(drb.isSelected())
{
if(unit<=200)
{
charge = unit * 2.45 ;
}
else if(unit <= 400 && unit >200)
{
charge = (unit - 200) * 3.95 + (200 * 2.45) ;
}
else if(unit >400)
{
charge = (unit - 400) * 4.65 + (200 * 2.45) + (200 * 3.95) ;
}
}
else if(nrb.isSelected() && uprb.isSelected())
{
charge = unit * 5.40 ;
}
else if(nrb.isSelected() && aboverb.isSelected())
{
charge = unit * 4.92 ;
}
else if(arb.isSelected() && uprb.isSelected())
{
charge = unit * 1.55 ;
}
else if(arb.isSelected() && aboverb.isSelected())
{
charge = unit * 9.84 ;
}
else if(irb.isSelected() && uprb.isSelected())
{
charge = unit * 5.05 ;
}
else if(irb.isSelected() && aboverb.isSelected())
{
charge = unit * 4.40 ;
}
JOptionPane.showMessageDialog(rootPane, "Electricity charge = " + charge);



Q7. Computech Company has number of employees who are divided into four grades as per their basic pay as the following:

GRADE I Basic : Rs.20,000p.m or more
D.A : 40% of Basic
H.R : 30%of Basic
GRADE II Basic : Rs.15,000 p.m. more but
less than.10,000
D.A. : 40% of Basic
H.R. : 25% of Basic
GRADE III Basic : Rs. 15,000 p.m. or
more but less than Rs. 12,000
D.A. : 30% of Basic
H.R. : 20% of Basic
GRADE III Basic : Rs. 15,000 p.m. or
more but less than Rs. 12,000
D.A. : 30% of Basic
H.R. : 20% of Basic


If the salary, which is the total of Basic, D.A. and H.R.A. calculate the tax as follows:

Annual Salary                             Tax

Less than 150000 
>=150000 and <250000            10%
>=250000                                    15%

i.            Write the code for Calculate button to find the DA, HRA, Gross, Annual Salary, Total Tax, Monthly Tax, and Netsalary.
                 (Gross=Salary+DA+HRA)(Net =Gross –Monthly Tax), (Total tax=Annual Salary Tax%),
(Annual Salary = Monthly Gross salary *12) (Monthly Tax = Total Tax /12)
       ii.            Write the code for Exit button to exit application.
Solution:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
double bs,da=0,hra=0,gs,anns,annt,mt,ns=0;
String grade;
bs=Double.parseDouble(txtSal.getText());
if(bs>=20000)
grade="I";
else if(bs>=15000)
grade="II";
else if(bs>=12000)
grade="III";
else
grade="IV";
if (grade.equals("I"))
{
da=bs*40/100;
hra=bs*30/100;
}
else if(grade.equals("II"))
{
da=bs*40/100;
hra=bs*30/100;
}
else if(grade.equals("III"))
{
da=bs*40/100;
hra=bs*30/100;
}
else if(grade.equals("VI"))
{
da=bs*40/100;
hra=bs*30/100;
}
gs=bs+da+hra;
anns=gs*12;
if(anns<150000)
annt=0;
else if(anns<250000)
annt=anns*10/100;
else
annt=anns*15/100;
mt=annt/12;
ns=gs-mt;
txtDa.setText(""+da);
txtHra.setText(""+hra);
txtGross.setText(""+gs);
txtTotTax.setText(""+annt);
txtNetSal.setText(""+ns);
txtAnnSal.setText(""+anns);
txtMonTax.setText(""+mt);
jLabel2.setText("Grade"+grade);
}

Q8. Create a Java Desktop application to find the area of circle,rectangle,circumference of circle and area of square. Design the IDE and programming logic with two JPanel containers contains the following

1. Add three JRadioButtons and set the buttons as: Circle, Rectangle and Square – Jpanel
2. Add four JCheckBoxes and set the buttons as :Area ,Perimeter ,Circumference

When you select an option from JPanel1, it automatically hide the facilities which is not appropriate for selected option. Similarly, apply the same for JTextfield controls also.
(i)Write the code for circle JRadioButton to make available the display controls which are appropriate for Circle operation.
(ii)Write the code for Rectangle JRadioButton to make available the display controls which are appropriate for Rectangle operation.
(iii)Write the code for Square JRadioButton to make available the display controls which are appropriate for Square operation.
(iv)Write the code for Calculate button to calculate the desired operations which you choose from JRadioButtons.
(v)Write the code for Exit button to exit application.
Solution:
import javax.swing.JOptionPane;
public class NewJFrame18 extends javax.swing.JFrame {
public NewJFrame18() {
initComponents();
}
public int area1(int x,int y){
return x*y;}
public int area2(int x){
return x*x;
}
public double area3(int x){
return 3.14*x*x;
}
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setVisible(true);
jLabel1.setVisible(true);
jTextField2.setVisible(true);
jLabel2.setVisible(true);
jTextField3.setVisible(true);
jLabel3.setVisible(true);
jTextField4.setVisible(true);
jLabel4.setVisible(true);
jCheckBox1.setVisible(true);
jCheckBox2.setVisible(true);
jCheckBox3.setVisible(true);
jCheckBox4.setVisible(true);
jCheckBox2.setVisible(false);
jTextField1.setVisible(false);
jLabel1.setVisible(false);
jTextField3.setVisible(false);
jLabel3.setVisible(false);
jTextField4.setVisible(false);
jLabel4.setVisible(false);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setVisible(true);
jLabel1.setVisible(true);
jTextField2.setVisible(true);
jLabel2.setVisible(true);
jTextField3.setVisible(true);
jLabel3.setVisible(true);
jTextField4.setVisible(true);
jLabel4.setVisible(true);
jCheckBox1.setVisible(true);
jCheckBox2.setVisible(true);
jCheckBox3.setVisible(true);
jCheckBox4.setVisible(true);
jCheckBox3.setVisible(false);
jCheckBox4.setVisible(false);
jTextField2.setVisible(false);
jLabel2.setVisible(false);
jTextField4.setVisible(false);
jLabel4.setVisible(false);
}
private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setVisible(true);
jLabel1.setVisible(true);
jTextField2.setVisible(true);
jLabel2.setVisible(true);
jTextField3.setVisible(true);
jLabel3.setVisible(true);
jTextField4.setVisible(true);
jLabel4.setVisible(true);
jCheckBox1.setVisible(true);
jCheckBox2.setVisible(true);
jCheckBox3.setVisible(true);
jCheckBox4.setVisible(true);
jCheckBox3.setVisible(false);
jCheckBox4.setVisible(false);
jTextField1.setVisible(false);
jLabel1.setVisible(false);
jTextField2.setVisible(false);
jLabel2.setVisible(false);
jTextField3.setVisible(false);
jLabel3.setVisible(false);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
double area=0,c=0,d=0,p=0;
if(jRadioButton1.isSelected())
{
int r=Integer.parseInt(jTextField2.getText());
area=area3(r);
c=6.28*r;
d=2*r;
if(jCheckBox1.isSelected())
JOptionPane.showMessageDialog(null,"area="+ area);
if(jCheckBox3.isSelected())
JOptionPane.showMessageDialog(null,"circumference="+ c);
if(jCheckBox4.isSelected())
JOptionPane.showMessageDialog(null,"diameter="+ d);
}
if(jRadioButton2.isSelected())
{
int l=Integer.parseInt(jTextField1.getText());
int b=Integer.parseInt(jTextField3.getText());
area=area1(l,b);
p=2*l+2*b;
if(jCheckBox1.isSelected())
JOptionPane.showMessageDialog(null,"area="+ area);
if(jCheckBox2.isSelected())
JOptionPane.showMessageDialog(null,"perimeter="+ p);
}
if(jRadioButton3.isSelected())
{
int r=Integer.parseInt(jTextField4.getText());
area=area2(r);
p=4*r;
if(jCheckBox1.isSelected())
JOptionPane.showMessageDialog(null,"area="+ area);
if(jCheckBox2.isSelected())
JOptionPane.showMessageDialog(null,"perimeter="+ p);
}

Q9. Hotel Hill Top Inn in Ooty plan to go for computerization in order to meet the workload during tourist session. There are three types of rooms available in Hill Top.

(a)Write the code to disable the text boxes txtRate,txtAmount.txtFacility when the form activated.
(b)Write the code for cmdClear command button to clear all the textboxes.
(c)Write the code for cmdRate to calculate rate of the room per day and display it in txtRAte depending on the type of room selected by the customer. Rate is calculated according to the following table:
Room Type
 Rate per day
Single
1500
Double
2800
Delux
5000

(d)Write the code for cmdAmount to calculate the total amount and display it in txtAmount.The total amount is calculated by first finding the cost of facilities selected by the customer. Cost of facilities is calculated according to the following table:
Facility
Cost
Tour Pacage
7000
Gym
2000
Laundry
1000





Solution:
public class NewJFrame15 extends javax.swing.JFrame {
public NewJFrame15() {
initComponents();
jTextField4.setEnabled(false);
jTextField5.setEnabled(false);
jTextField3.setEnabled(false);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField3.setEnabled(true);
Facility Cost
Tour Package 7000
Gym 2000
Laundry 1000
int r=0;
if(jRadioButton1.isSelected())
r=1500;
else if(jRadioButton2.isSelected())
r=2800;
else if(jRadioButton3.isSelected())
r=5000;
jTextField3.setText(""+r);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField4.setEnabled(true);
jTextField5.setEnabled(true);
int n;
double r,c=0,amt;
n=Integer.parseInt(jTextField2.getText());
r=Double.parseDouble(jTextField3.getText());
if(jCheckBox1.isSelected())
c=c+7000;
if(jCheckBox2.isSelected())
c=c+2000;
if(jCheckBox3.isSelected())
c=c+1000;
amt=r*n+c;
jTextField4.setText(""+c);
jTextField5.setText(""+amt); }
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText(""); }

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}

Q10. Common Wealth International is a bank. The bank provides three types of loans –Car loan, House loan,Education loan.

(a)Write the command for Clear button to clear all the text boxes and set car loan as default loan type.
(b)Write the command s for Show Interest Amount button to show the interest rate in txtRate according to the following criteria :
Car loan –10%
House loan –8.5%
Education loan –5%
(c)Write the commands for Calculate Discount button to find discount on an amount and amount after discount.
Notice that the bank provides discount on loan amount according to following criteria: - If the amount<= 10,000,00 then 0.20% discount. - If amount > 10,000,00 then 0.25% discount.
The Net amount = Interest Amount –discount amount
Solution:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jRadioButton1.setSelected(true);
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
double amt,iamt,disc,netamt;
amt=Double.parseDouble(jTextField1.getText());
if(amt<=1000000)
disc=0.20*amt/100;
else
disc=0.25*amt/100;
iamt=Double.parseDouble(jTextField3.getText());
iamt=iamt-disc;
netamt=amt+iamt;
jTextField3.setText(""+iamt);
jTextField4.setText(""+disc);
jTextField5.setText(""+netamt);
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
double r=0;
if(jRadioButton1.isSelected())
r=10;
else if(jRadioButton2.isSelected())
r=8.5;
else if(jRadioButton3.isSelected())
r=5;
double amt,iamt;
amt=Double.parseDouble(jTextField1.getText());
iamt=amt*r/100;
jTextField2.setText(""+r);
jTextField3.setText(""+iamt);
}

Q11. Mr. Verma of ICICI Bank frequently needs to calculate the interest and amount due for his clients. He ask his software programmer to design an interest calculator which will calculate the compound interest and amount due. The bank offers two different accounts fixed deposit and recurring deposit with different rage criteria. The programmer uses Java language with NetBeans IDE to develop this program

(a) Write the code to disable the text boxes txtInterest,txtAmount,txtRate and txtDate in the form when the form activated.
(b) Write the code for cmdClear command button to clear all the textboxes and checkbox except txtDate.Set the default choice in the option button as Fixed deposit.
(c) Write the code for the click event of the command button cmdCalculate to calculate compound interest ,amount,display the values in textboxes txtInterest and txtAmount depending on the principal,rate and time.
Note that the compounded amount is calculated as P*(1+r/100)^T
Interest as Compounded Amount - Principal
Rate is calculated based on the time according to the following table.
Account
Time(in yrs)
 Rate
Fixed Deposit

<=1
>1 and <=5
>5
10%
12%
15%
Recurring Deposit

<=2
>2 and <=7
>7
10%
12%
15%
An additional rate of 2% is given to senior citizens.if the chkSR checkbox is checked.
(d) Write the code for cmdExit to exit the application.
Solution:
public class NewJFrame17 extends javax.swing.JFrame {
/** Creates new form NewJFrame17 */
public NewJFrame17() {
initComponents();
jTextField3.setEnabled(false);
jTextField4.setEnabled(false);
jTextField5.setEnabled(false);
jTextField6.setEnabled(false);
}
jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jTextField3.setEnabled(true);
jTextField5.setEnabled(true);
jTextField6.setEnabled(true);
double p,r=0,t,iamt,amt;
p=Double.parseDouble(jTextField1.getText());
t=Double.parseDouble(jTextField2.getText());
if(jRadioButton1.isSelected())
{
if(t<=1)
r=10;
else if(t<=5)
r=12;
else
r=15;
}
if(jRadioButton2.isSelected())
{
if(t<=2)
r=10;
else if(t<=7)
r=12;
else
r=15;}
if(jCheckBox1.isSelected())
r=r+2;
iamt=p*Math.pow((1+r/100),t)-p;
amt=p+iamt;
jTextField3.setText(""+r);
jTextField5.setText(""+iamt);
jTextField6.setText(""+amt); }
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton1.setSelected(true);
jCheckBox1.setSelected(false);
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField5.setText("");
jTextField6.setText("");
// TODO add your handling code here:
}


Q12. Read the following case study and answer the questions that follows :
Mr.Goyal is working in a multi-national company. His family members visit a shopping mall and purchased variety of products including garments. The total amount goes into some thousands. The owner of the shopping mall provides handsome discounts of credit cards as :

Card Type
Discount
HDFC
12%
ICIC
10%
Visa
9.5%
Axis
10.5%
Standard chartered
8.5%
City Bank
11.5%
SBI
8%


(a) Write the command for Discount button to compute discount amount and net amount.
(b) Write the code for cmdClear command button to clear all the text boxes and set the default choice in the radio button as SBI.
(c)Write the code for Exit button to close the application.
Solution:
// code for discount button
double amt=Double.parseDouble(txtAmount.getText());
double disc;
If(optHdfc.isSelected())
{
disc=0.12*amt;
}
else if(optICICI.isSelected())
{
disc=0.10*amt;
}
else if(optVisa.isSelected())
{
disc=0.095*amt;
}
else if(optAxis.isSelected())
{
disc=0.105*amt;
}
else if(optCharted.isSelected())
{
disc=0.085*amt;
}
else if(optCity.isSelected())
{
disc=0.115*amt;
}
else if(optSBI.isSelected())
{
disc=0.08*amt;
}
txtDiscAmount.setText(“ “+disc);
double net=amt-disc;
txtNet.setText(“ “+ net);

//code for clear all button
txtAmount.setText(“ “);
txtDiscAmount.setText(“ “);
txtNet.setText(“ “);
optSBI.setSelected(true);

//Code for exit button
System.exit(0);