Class 12 Informatics Practices Practical List with Code

this is an old list of year 2015 of sks, Kolkata School.

Question 1 –

Code for Add button

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

jTextArea1.append("Roll no. : " + jTextField1.getText() + "\n");

jTextArea1.append("Name : " + jTextField2.getText() + "\n");

jTextArea1.append("Class : " + jTextField3.getText() + "\n");

jTextArea1.append("English mark : " + jTextField4.getText() + "\n");

jTextArea1.append("Accounts mark : " + jTextField5.getText() + "\n");

jTextArea1.append("Economics mark : " + jTextField6.getText() + "\n");

jTextArea1.append("Business study mark : " + jTextField7.getText() + "\n");

jTextArea1.append("Informatics practices mark : " + jTextField8.getText());

}

Code for Exit Button

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


Question 2 to Question 19 are locked. To unlock login with your facebook account by clicking the f button below and share the link with your friends. Sharing is caring.

 
                            
                           
                              [indeed-social-locker
 sm_list=’fb’ sm_template=’ism_template_9′ sm_list_align=’vertical’
sm_display_counts=’true’ sm_display_full_name=’true’ locker_template=2
sm_d_text=’

Programs 2 to 19 is locked

Share
 This Page on Facebook To view all programs ! click the facebook button
below

‘ ism_overlock=’default’ ]

Question 2:


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

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        int num1, num2;
    int sum = 0, diff = 0, mult = 0;
    double div1 = 0;
    int result = 0;
        num1 = Integer.parseInt(txtNum1.getText());
        num2 = Integer.parseInt(txtNum2.getText());
        sum = num1 + num2;
    diff = num1 - num2;
    mult = num1 * num2;
    div1 = num1 / num2;
        txtAdd.setText(Integer.toString(sum));
        txtSub.setText(Integer.toString(diff));
        txtMul.setText(Integer.toString(mult));
        txtDiv.setText(Double.toString(div1));
    }

Question 3:

If the Bill amount is more than Rs.25,000/- then the customer gets an additional
offer of 5% Write the Juva code for the following :
(a) To assign Additional offer as 0(jTextField4) and Net amount as 0 (jTextField5). Also set them as un-editable.
Answer:

jTextField4.setText("0") ; 1
jTextField5.setText("0");
jTextField4.setEditable(false);
jTextField5.setEditable(false);

(b) [when “Calculate Offer”(JButton1) is clicked] To calculate discount as per the given criteria and display the same in
jTextField3 To assign Additional offer (jTextField4) as 5% of amount(jTextField2) as per the above condition.
To enable “Calculate Net Amount”(jButton2) button

Answer:

 double Offer, Aoffer ; 2
int Amount = Integer.parseInt(JTextField2.getText ( ));
if (jRadioButton1.isSelected ( ) == true)

Offer = 0.2*Amount;

else if(jRadioButton2.isSelected ( ) == true)
Offer = 0.15*Amount ;
else if (jRadioButton3.isSelected ( ) == true)
Offer = 0.1*Amount ;
jTextField3.setText (“”+0ffer) ;

if (Amount > 25000)
Aoffer=0.5*Amount ;
jTextField4.setText (""+Aoffer);
jButton2.setEnabled(true);

c. [When “Calculate Net Amount” (jButton2) is clicked] To calculate net amount as [TotalCost(jTextField2)]-offer(jTextField3)
-Additional offer (jT extField4)] To display the net amount in jTextField5

int AmoUut = Integer.parseInt(jTextField2.getText( )) ;
double Offer = Double.parseDouble(jTextField3.getText( )) ;
double Aoffer = Double.parseDouble (jTextField4.getText ( )) ;
double Total = Amount-Offer-Aoffer;
jTextField5.setText(""+Total) ;

 


Question 4

 

Solution

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int sn, ln; // To hold starting number and last number
sn = Integer.parseInt(jTextField1.getText());
ln = Integer.parseInt(jTextField2.getText());
for (int ctr = sn; ctr <= ln; ctr = ctr + 2) {
jTextArea1.append("" + ctr + " ");
}
}

(ii) To clear the text area on clicking [reset] button

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

jTextField1.setText("");
jTextField2.setText("");
jTextArea1.setText(null);
}

(iii) To terminate the application on clicking the stop button

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

System.exit(0);
}

 


Question 5

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int num1, num2, num3;
int max;

num1 = Integer.parseInt(jTextField1.getText());
num2 = Integer.parseInt(jTextField2.getText());
num3 = Integer.parseInt(jTextField3.getText());

if (num1 > num2   &&num1 > num3)

{

max = num1;

}

else if (num2 > num3)

{

max = num2;

}

else  max = num3;

jLabel1.setText("Greater number is : " +max);

}

b. Write code for exit button to exit application

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

 


Question 6

Answer

a.

private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {
txtTCost.enable(false);
optWhole.setSelected(true);
}

b.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int ordUnit;
float TCost=0;
float Discount = 0 ;
ordUnit=Integer.parseInt(txtUnit.getText());
if (optWhole.isSelected())
{
if (ordUnit >= 1 &&ordUnit <= 15)    
 TCost = ordUnit * 50;   
else if (ordUnit >= 16 &&ordUnit <= 20) 
  TCost = ordUnit * 45;  
else if (ordUnit >= 21 &&ordUnit <= 30)
   TCost = ordUnit * 40;  
 else if (ordUnit >= 31 &&ordUnit <= 50)
  TCost = ordUnit * 35;  else if (ordUnit > 50)
 TCost = ordUnit * 30;
}
else if (optRetail.isSelected())
{
if (ordUnit >= 1 &&ordUnit <= 15)  
 TCost = ordUnit * 60; 
 else if (ordUnit >= 16 &&ordUnit <= 20)
   TCost = ordUnit * 55; 
  else if (ordUnit >= 21 &&ordUnit <= 30)
   TCost = ordUnit * 50; 
  else if (ordUnit >= 31 &&ordUnit <= 50)  
 TCost = ordUnit * 45;  
else if (ordUnit > 50)
TCost = ordUnit * 40;
}

if (chkSpecial.isSelected())
Discount = TCost * (float)0.1;
txtDisc.setText(Float.toString(Discount));
txtTCost.setText(Float.toString(TCost));
}

Question 7

Answer

(i)

private void chkSumActionPerformed(java.awt.event.ActionEvent evt)
int N1, N2, sum = 0;
N1 = Integer.parseInt(txtN1.getText());
N2 = Integer.parseInt(txtN2.getText());
sum = N1 + N2;
jLabel3.setText("Sum is : " + sum);
}

 

(ii)

private void chkDiffActionPerformed(java.awt.event.ActionEvent evt) {
int N1, N2, diff = 0;
N1 = Integer.parseInt(txtN1.getText());
N2 = Integer.parseInt(txtN2.getText());

diff = N1 - N2;
jLabel3.setText("The difference between " + N1 + " and " + N2 + " is = " + diff);
}



Question 8:

1. (a)  Write the code for Calculate Total, Percentage  & Grade  button (named as cmdCalc) to calculate total (txtTotal), percentage (txtPer) and grade (txtGr). Also display the same in respective text boxes.

private void cmdCalcActionPerformed(java.awt.event.ActionEvent evt) {
        int R, eng, acc, bst, inf, eco, tot;  
        float per;
        String Name, Gr="";
        R = Integer.parseInt(txtRoll.getText());
        eng = Integer.parseInt(txtEng.getText());
        acc = Integer.parseInt(txtAcc.getText());
        bst = Integer.parseInt(txtBst.getText());
        inf = Integer.parseInt(txtInf.getText());
        eco = Integer.parseInt(txtEco.getText());
        
        tot = eng + acc + bst + inf + eco;
        
        per = (tot / 500) * 100 ;
        if (per >= 90)
            Gr = "A+";
        else
            if (per >= 80 &&per < 90)   
               Gr = "A";  
        else  if (per >= 70 &&per < 80) 
                  Gr = "B";
        else if (per >= 60 &&per < 70)   
               Gr = "C";        
        else if (per >= 50 &&per < 60)
                Gr = "D";
        else if (per < 50)
                Gr = "F";
        
        txtTotal.setText(Integer.toString(tot));
        txtPer.setText(Float.toString(per));
        txtGr.setText(Gr);
    }

b.Write the code for Exit button to exit application

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

 

 


Question 9

 

A JPanel container is used for card types with JRadioButton controls as follow :
jRadioButtonl  : HDFC (optHDFC) with buttonGroupl
jRadioButton2 : ICICI (optICICI) with buttonGroupl
jRadioButton3 : Visa (optVisa) with buttonGroupl
jRadioButton4 : Axis (optAxis) with buttonGroupl
jRadioButton5 : Standard Charted (optSC) with buttonGroupl
jRadioButton6 : City Bank (optCity) with buttonGroupl
jRadioButton7 : SBI (optSBI) with buttonGroupl
Enter the shopping amount (txtAmount) and do the following :

(a) Write the command for Discount button (named as cmdDisc) to compute discount amount (named
as txtDisc) and net amount (named as txtNet).

private void cmdDiscActionPerformed(java.awt.event.ActionEvent evt) {
        
        double discount=0;
        double netamount=0;
        double Amount = Double.parseDouble(txtAmount.getText());
        if (optHDFC.isSelected())
            discount = Amount * 12/100;
        else
            if (optICICI.isSelected())
            discount = Amount * 10/100;
        else
            if (optVisa.isSelected())
            discount = Amount * 9.5/100;
        else
            if (optAxis.isSelected())
            discount = Amount * 10.5/100;
        else
            if (optSC.isSelected())
            discount = Amount * 8.5/100;
        else
            if (optCity.isSelected())
            discount = Amount * 11.5/100;
        else
            if (optSBI.isSelected())
            discount = Amount * 8/100;
        netamount = Amount - discount;
        txtDisc.setText(String.valueOf(discount));
        txtNet.setText(String.valueOf(netamount));
    }

(b)  Write the code for Clear button (named as cmdClear) to clear all the text boxes and set the default
choice in the radio button as SBI.

private void cmdClearActionPerformed(java.awt.event.ActionEvent evt) {
        txtAmount.setText("");
        txtDisc.setText("");
        txtNet.setText("");
        optSBI.setSelected(true);  // Default button selected
    }

Question 10
Hotel Hill Top Inn in Ooty plans to go for computerization in order to meet the workload during tourist
season. There are 3 types of rooms available in Hill Top. The following is the data entry screen used to
generate bill:

Enter Customer Name (txtName and No. of Days (txtDays) and do the following :
(a)  Write  the  code  to  disable  the  text  boxes Rate (txtRate), Cost of facilities (txtFacility), and Amount (txt Amount) when the form activated.

private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {
        txtRate.enable(false);
        txtAmount.enable(false);
        txtFacility.enable(false);
    }

(b) Write  the  code  for  Clear  button (named as cmdClear) to clear all the textboxes  and  uncheck  all jRadioButtons  and  jCheckBox controls.

private void cmdClearActionPerformed(java.awt.event.ActionEvent evt) {
        txtRate.setText("");
        txtFacility.setText("");
        txtAmount.setText("");
        OptSingle.setSelected(false);
        OptDouble.setSelected(false);
        OptDelux.setSelected(false);
        chkTour.setSelected(false);
        chkGym.setSelected(false);
        chkLaundry.setSelected(false);
    }

(c)  Write  the  code  for  Calculate  Rate button  (named  as  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   Rate per day
Single   1500
Double   2800
Delux   5000

private void cmdRateActionPerformed(java.awt.event.ActionEvent evt) {
        
        if (OptSingle.isSelected())
            txtRate.setText(Integer.toString(1500));
        else
            if (OptDouble.isSelected())
                txtRate.setText(Integer.toString(2800));
            else
                if (OptDelux.isSelected())
                    txtRate.setText(Integer.toString(5000));
    }

d. Write  code  for Calculate Amount button  (named  as cmdAmount)  to calculate  the total  amount
(txtRate * txtDays + txtFacility) and display it in txtAmount text box. 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 Package         7000
Gym                  2000
Laundry              1000

private void cmdAmountActionPerformed(java.awt.event.ActionEvent evt) {

        if (chkTour.isSelected())
            txtFacility.setText(Integer.toString(7000));
        else
            if (chkGym.isSelected())
                txtFacility.setText(Integer.toString(2000));
            else
                if (chkLaundry.isSelected())
                    txtFacility.setText(Integer.toString(1000));
        Double TAmount = (Double.parseDouble(txtRate.getText()) *  Double.parseDouble(txtDays.getText())) + Double.parseDouble(txtFacility.getText());

        txtAmount.setText(Double.toString(TAmount));
    }


Question 11
Read the following case study and answer the questions that follows :
AVON Tools has computerized its billing system. The following is the data Entry screen in NetBeans
IDE used by them :

A JPanel container is used for Caregory of City with JRadioButton controls as follow :
•  jRadioButtonl  : A (optA) with buttonGroupl
•  jRadioButton2 : B (optB) with buttonGroupl
•  jRadioButton3 : C (optC) with buttonGroupl
Enter Product ID (txtPID), Product Description (txtDesc), Quantity (txtQty), Unit Price (txtPrice) and
do the following:

(a) When the user clicks Clear button (named as cmdClear), all the values stored in the text boxes and
option button should be cleared and set the default category of city as A

 private void cmdClearActionPerformed(java.awt.event.ActionEvent evt) {
        txtECode.setText("");
        txtEName.setText("");
        txtBasic.setText("");
        txtPHour.setText("");
        txtHRA.setText("");
        txtCCA.setText("");
        txtTHour.setText("");
        txtDays.setText("");
        txtSalary.setText("");
        txtOTAmount.setText("");
        txtTSalary.setText("");
        optPer.setSelected(false);         
        optTemp.setSelected(false);                 
    }

(b) When the Calculate button (named as cmdCalc) is clicked, Sub Total  (txtSub), Tax 6.50% (txtTax),
Delivery and Handling Charges (txtCharge) and Total (txtTotal) amount are computed and displayed.
The criterion for calculation of Delivery and Handling Charges is as given below :
Category of City Charges
A 2,000
B 3,000
C 3,500
•  Sub Total is calculated by multiplying Quantity with Unit Price.
•  Tax is calculated as 6.50% of Sub Total.
•  Total is calculated as the sum of Sub Total, Tax, Delivery and Handling Charges.

 private void cmdCalcActionPerformed(java.awt.event.ActionEvent evt) {
        float basic = 0;
        float HRA = 0;
        float CCA = 0;
        int oPOur = 0, oTOur=0; 
        int NDays;
        float OverTimeAmount=0;
        float salAmt=0, TotalAmount=0;
        
        if (optPer.isSelected())
        {
            basic = Float.parseFloat(txtBasic.getText());
            oPOur = Integer.parseInt(txtPHour.getText());
            HRA = basic * 10/100;
            OverTimeAmount = oPOur * 75;
            CCA = 500;
            txtCCA.setText(String.valueOf(CCA));
            txtHRA.setText(String.valueOf(HRA));
           
            salAmt = basic + HRA + CCA;
        }
        else
        
        if (optTemp.isSelected())
        {
            oTOur = Integer.parseInt(txtTHour.getText());
            NDays =Integer.parseInt(txtDays.getText());
            OverTimeAmount = oTOur * 50;
          
            salAmt = NDays * 250;
        }
        // finding total salary
        TotalAmount = salAmt + OverTimeAmount;
        // showing salary, overtime amount and total salary
        txtSalary.setText(String.valueOf(salAmt));
        txtOTAmount.setText(String.valueOf(OverTimeAmount));
        txtTSalary.setText(String.valueOf(TotalAmount));
        optPer.setSelected(false);         
        optTemp.setSelected(false);         
    }


Question 12

Read the following case study and answer the questions that follows :
The  Pizza Cafe has  computerized  its billing. The following is the data entry screen used at their outlet.  The  outlet offers  two  different  types  of pizzas, regular and pan pizzas. The price of a regular pizza is Rs. 220 and that of a pan pizza is  Rs.  260.  The  user  can  choose three different types of extra toppings.Extra toppings costs as :

Extra toppings costs as :

There are two JPanel containers used for Pizza Type and Toppings:
Pizza Type with JRadioButton controls as follow :
•  jRadioButtonl  : Regular (optRegular) with buttonGroupl
•  jRadioButton2 : Pan (optPan) with buttonGroupl
Toppings with JCheckBox controls as follow :
•  jCheckBoxl: Cheese (chkCheeseRegular)
•  jCheckBox2 : Capsicum (chkCap)
•  jCheckBox3 : Pepperonion (chkPep)
Enter the Customer name (txtName), Quantity (txtQty) and write the code for the following :

(a) Write the code for Calculate Rate button (named as cmdCalcRate) to calculate the rate of the pizza
and display the Rate in a text box (txtRate) depending on the type of pizza selected by the customer

private void cmdCalcRateActionPerformed(java.awt.event.ActionEvent evt) {
        if (optRegular.isSelected())
            txtRate.setText(String.valueOf(220)); 
        else
            if (optPan.isSelected())
                txtRate.setText(String.valueOf(260));

    }

(b) Write the code for Calculate Amount button (named as cmdAmount) to calculate the total amount:
and display it in txtAmount. The total amount is calculated by first finding the cost of extra topping
(txtTop) selected by the customer. Remember that each extra topping adds the value with previous topping. Then add it to the rate and multiply the resultant amount by the quantity ordered.

private void cmdCalcAmtActionPerformed(java.awt.event.ActionEvent evt) {
        int Top = 0;
        float Amt = 0; 
        // Finding topping cost
        if (chkCheese.isSelected())
        {
            Top = 40;
        }
        if (chkCap.isSelected())
        {
            Top = Top + 20;
        }
        if (chkPep.isSelected())
        {
            Top = Top + 25;
        }
        txtTop.setText(Integer.toString(Top));
       
        Amt = (Integer.parseInt(txtRate.getText()) + Top) * Integer.parseInt(txtQty.getText());
        txtAmount.setText(Float.toString(Amt));
    }

c. Write the code for Clear button to clear all the text boxes and make default to Regular Pizza type and Cheese as Topping

 private void cmdClearActionPerformed(java.awt.event.ActionEvent evt) {
        txtName.setText("");
        txtQty.setText("");
        txtRate.setText("");
        txtTop.setText("");
        txtAmount.setText("");
        optRegular.setSelected(true);
        chkCheese.setSelected(true);
        chkCap.setSelected(false);
        chkPep.setSelected(false);
    }

Question 13:
Read the following case study and answer the questions that follow :
Mr. Vidyarthi works in Blossoms Public School as a programmer. He is required to develop a student record. The school offers two different streams : medical and non-medical, with different grading criteria.
The school also offers incentive to the NCC cadets in the form of a 3% increment in percentage for all the NCC cadets. The grading criteria for the two streams is given below :

There is a JPanel containers which is used for Medical and Non-Medical:
•  jRadioButtonl  : Medical (OptMed) with buttonGroupl
•  jRadioButton2 : Non-Medical (OptNMed) with buttonGroupl

and a jCheckBoxl  control for NCC Cadet (chkNCC).
In the data entry form enter First Term Marks (txtFirst), Second Term Marks (txtSecond), select Stream
and/or NCC Cadet and write the code for the following :

(a) Write the code to disable the text boxes for Percentage (txtPercentage) and Grade (txtGrade). Also,
set Medical as default stream.

 private void btnDisActionPerformed(java.awt.event.ActionEvent evt) {
        txtPer.enable(false);
        txtGr.enable(false);
        optMed.setSelected(true);  // Default button selected
        optNMed.setSelected(false);
    }

b.Write the code for Calculate Percentage button (named as cmdCalcPer) to calculate the percentage
after finding the total marks of first term and second term (assuming that both marks are out of 100).
Also ensure that NCC cadets (chkNCC) get an increment of 3% in their percentages.

private void cmdCalcPerActionPerformed(java.awt.event.ActionEvent evt) {
        int fTerm, sTerm;
        int Total=0;
        float per=0;
        fTerm = Integer.parseInt(txtFirst.getText());
        sTerm = Integer.parseInt(txtSecond.getText());
        Total = fTerm + sTerm; 
        per = Total/2; 
        if (chkNCC.isSelected())
            per = per + 3; // Extra 3% for NCC
        // Displaying percentage
        txtPer.setText(Float.toString(per));
    }

(c)  Write the code for Calculate Grade button (named as cmdCalcGrade) to calculate the grade depending
on the stream selected according to the criteria given above

private void cmdCalcGradeActionPerformed(java.awt.event.ActionEvent evt) {
        float per = Float.valueOf(txtPer.getText());
        String gr="";
        // Medical 
        if (optMed.isSelected())
        {
            if (per >= 80)
                gr = "A";
            else
                if (per >= 60 &&per <= 79)
                    gr = "B";
                else
                    if (per < 60)
                        gr = "C";
        }
        // Non-Medical 
        else
            if (optNMed.isSelected())
            {
                if (per >= 75)
                    gr = "A";
                else
                    if (per >= 50 &&per <= 74)
                        gr = "B";
                    else
                        if (per < 50)
                            gr = "C";
        }
        txtGr.setText(gr);
    }

d. Write the code for Clear button (named as cmdClear) to clear all the text boxes and the check box
and Medical as default stream

private void cmdClearActionPerformed(java.awt.event.ActionEvent evt) {
        txtFirst.setText("");
        txtSecond.setText("");
        txtPer.setText("");
        txtGr.setText("");
        chkNCC.setSelected(false);
        optMed.setSelected(true);  // Default button selected
        optNMed.setSelected(false);
    }


Question 14
Mr.  Sharma  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:

There is a JPanel containers which is used
for Account Type :
•  jRadioButtonl  : Fixed Deposit (optFD) with buttonGroupl
•  jRadioButton2 : Non-Medical (optRD) with buttonGroupl
and a jCheckBoxl control for Sr. Citizen (chkSR).
In the data entry form enter Principal (txtPrincipal), Time (txtTime) Rate (txtRage), select an account
type and/or Sr. Citizen and write the code for the following :

(a) Add the import statement which will help to display the current calendar date

import java.util.Date;
import java.text.DateFormat;

(b) Write the code to disable the text boxes Interest (txtlnterest), Amount (txtAmount), Rate (txtRate)
and Date (txtDate) in the form when the form activated

 private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {
        txtInterest.enable(false);
        txtAmount.enable(false);
        txtRate.enable(false);
    }

(c)Write  the code for Clear button  (named as cmdClear) to clear all  the  text boxes and check box
except txtDate. Set the default choice in the option button as Fixed Deposit.

private void cmdClearActionPerformed(java.awt.event.ActionEvent evt) {
        txtPrincipal.setText("");
        txtTime.setText("");
        txtRate.setText("");
        txtInterest.setText("");
        txtAmount.setText("");
        txtDate.setText("");
        optFD.setSelected(true);  
        optRD.setSelected(false); 
    }

d.Write the code for Calculate button (named as cmdCalculate) to calculate compound interest and amount and display the values in text boxes : txtlnterest and txtAmound depending on the principal, rate and time.
Note that the compound interest is calculated as P*(l+r/100) A T &amount as Principal + Interest. Rate is calculated based on the time according to the following table.

An additional rate of 2% is given to senior citizens, i.e.,if the chkSR CheckBox is checked.

private void cmdCalculateActionPerformed(java.awt.event.ActionEvent evt) {

        int T = Integer.parseInt(txtTime.getText());
        double CI = 0, Amount =0;
        double P = Double.parseDouble(txtPrincipal.getText());
        float R = 0;
        if (optFD.isSelected())
        {
            if (T<=1)
                R = 10;
            else
                if ((T>1) &&(T<=5))
                    R = 12;
            else
                if (T>5)
                    R = 15;
        }
        else
            if (optRD.isSelected())
            {
                if (T<=2)
                    R = 10;
                else
                    if ((T>2) &&(T<=7))
                        R = 12;
                    else
                    if (T>7)
                        R = 15;
            }
        // code for sr citizen
        if (chkSR.isSelected())
            R = R + 2;
        
        txtRate.setText(Float.toString(R));
         CI = P * Math.pow((1 + (R/100)), T);
        
        Amount = P + CI;
        txtInterest.setText(String.valueOf(CI));
        txtAmount.setText(String.valueOf(Amount));
    }

Question 15

Design aGUI application (Sum) using Java nethod  to  find  the  sum  of  two  input numbers  in  two  text  boxes  (txtNl  and txtN2). Notice that the method will display the  sum  of two  numbers  in  a text field control after a button click. The following screen used to perform a Java method to find the sum of two input numbers :

a. Write a method called Sum_Num() to add integers and display the result in a text box called txtR.

public void Sum_Num( ) {
        int N1, N2, sum=0;
    N1 = Integer.parseInt(txtN1.getText());
    N2 = Integer.parseInt(txtN2.getText());
    sum = N1 + N2;
    txtR.setText(Integer.toString(sum));
    }
    

b. Write the code for find sum button’s (named as btnSum) click event procedure to call the Sum_Num() method

private void btnSumActionPerformed(java.awt.event.ActionEvent evt) {
      //calling function Sum_Num() 
       Sum_Num();
    }

Question 16 from Sumita Arora - Not done yet


Question 17

Answer the following :
(a) Write the command for Search button to display details of a students data according to roll numbers.
Otherwise display a suitable message if no record is found. Also, make the text boxes uneditable
when it displays the contents in respective JTextField controls

  import java.sql.*;
  import javax.swing.JOptionPane;
private void cmdSearchActionPerformed(java.awt.event.ActionEvent evt) {
        int rlno = Integer.parseInt(txtRoll.getText());
        String query = "SELECT * FROM Student WHERE rollno = " + rlno + ";";
        try {

           
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/school","root","kapil");
            
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(query);

            if (rs.next()) {
                String nrollno = rs.getString("rollno");
                String nName = rs.getString("name");
                String nAddress = rs.getString("address");
                String nsclass = rs.getString("sclass");
                String nsection = rs.getString("section");
                String ndob = rs.getString("dob");
                
                txtName.setText(nName);
                txtAdd.setText(nAddress);
                txtCls.setText(nsclass);
                txtSec.setText(nsection);
                txtDob.setText(ndob);
                
                txtName.setEditable(false);
                txtAdd.setEditable(false);
                txtCls.setEditable(false);
                txtSec.setEditable(false);
                txtDob.setEditable(false);
               
                con.close();
                stmt.close();
                rs.close();
            }
            else
            {
                JOptionPane.showMessageDialog(null, " NO student with this roll number in table");
            }
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(this, e.getMessage());
        }
    }

(b) Write the code for Exit button to exit application.

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


Question 18

Answer the following:
(a)  Write the command for Add button to add record into Student table.

import java.sql.*;
 import javax.swing.JOptionPane;
    private void cmdAddActionPerformed(java.awt.event.ActionEvent evt) {
        try {
                       
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = (Connection)
                    DriverManager.getConnection("jdbc:mysql://localhost:3306/school","root","reeta");
            Statement stmt = null;
            ResultSet rs = null;
            String SQL = "SELECT * FROM Student";
            stmt = con.createStatement();
            rs = stmt.executeQuery(SQL);

            int rlno = Integer.parseInt(txtRoll.getText());
            String nName = txtName.getText();
            String nAdd = txtAdd.getText();
            String nCls = txtCls.getText();
            String nSec = txtSec.getText();
            String nDob = txtDob.getText();
            String strSQL = "INSERT INTO Student(rollno, name, address, sclass, section, dob) VALUES ("+(rlno)+", '"+(nName)+"', '"+(nAdd)+"', '"+(nCls)+"', '"+(nSec)+"', '"+(nDob)+"')";
            int rowsEffected = stmt.executeUpdate(strSQL);
            JOptionPane.showMessageDialog(null, "Record added successfully into Student table");
            con.close();
            stmt.close();
            rs.close();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, e.getMessage());
        }
}

(b)  Write the command for Clear button to clear all text box contents

private void cmdClearActionPerformed(java.awt.event.ActionEvent evt) {
        txtRoll.setText("");
        txtName.setText("");
        txtAdd.setText("");
        txtCls.setText("");
        txtSec.setText("");
        txtDob.setText("");
    }

(c)  Write the code for Exit button to exit application.

private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExitActionPerformed
        System.exit(0);
}

Question 19:

Answer the following:
(a) Write the command for Search button to display a particular student information for deletion:

             import java.sql.*;
             import javax.swing.JOptionPane;

private void cmdSearchActionPerformed(java.awt.event.ActionEvent evt) {
        int rlno = Integer.parseInt(txtRoll.getText());
        String query = "SELECT * FROM Student WHERE rollno = " + rlno + ";";
        try {
             import java.sql.*;
             import javax.swing.JOptionPane;
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/school","root","kapil");
            
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(query);

            if (rs.next()) {
                String nrollno = rs.getString("rollno");
                String nName = rs.getString("name");
                String nAddress = rs.getString("address");
                String nsclass = rs.getString("sclass");
                String nsection = rs.getString("section");
                String ndob = rs.getString("dob");
                
                txtName.setText(nName);
                txtAdd.setText(nAddress);
                txtCls.setText(nsclass);
                txtSec.setText(nsection);
                txtDob.setText(ndob);
                
                txtRoll.setEditable(false);
                
                con.close();
                stmt.close();
                rs.close();
            } else {
                JOptionPane.showMessageDialog(null, "No record found of this roll number");
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, e.getMessage());
        }
}

b.  Write the command for Delete Student button to delete student record

 import java.sql.*;
 import javax.swing.JOptionPane;
private void cmdDelActionPerformed(java.awt.event.ActionEvent evt) {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = (Connection)
            DriverManager.getConnection("jdbc:mysql://localhost:3306/school","root","kapil");
            Statement stmt = null;
            ResultSet rs = null;
            String SQL = "SELECT * FROM Student";
            stmt = con.createStatement();
            rs = stmt.executeQuery(SQL);

            int rlno = Integer.parseInt(txtRoll.getText());
            String nName = txtName.getText();
            String nAdd = txtAdd.getText();
            String nCls = txtCls.getText();
            String nSec = txtSec.getText();
            String nDob = txtDob.getText();
            
            int opt = JOptionPane.showConfirmDialog(null, "Are you sure to delete this student?");
            if (opt == JOptionPane.YES_OPTION)
            {
                try {
                    String strSQL = "Delete from Student where rollno = " + (rlno);
                    int rowsEffected = stmt.executeUpdate(strSQL);
                    if (rowsEffected == 0)
                        JOptionPane.showMessageDialog(this, "Record does not exist");
                    else
                    {
                        JOptionPane.showMessageDialog(this,"Record Deleted");
                        
                        txtRoll.setText("");
                        txtName.setText("");
                        txtAdd.setText("");
                        txtCls.setText("");
                        txtSec.setText("");
                        txtDob.setText("");
                        txtRoll.setEditable(true);
                    }
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "Unable to delete");
                }
            }
            con.close();
            stmt.close();
            rs.close();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, e.getMessage());
        }
}


(c)  Write the command for Clear button to clear all text box contents

private void cmdClearActionPerformed(java.awt.event.ActionEvent evt) {
        txtRoll.setText("");
        txtName.setText("");
        txtAdd.setText("");
        txtCls.setText("");
        txtSec.setText("");
        txtDob.setText("");
        txtRoll.setEditable(true);
}

(d) Write the code for Exit button to exit application.

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


All THE BEST

 [/indeed-social-locker]