CLASS XI: PRACTICAL SOLUTION : INFORMATICS PRACTICES

CLASS XI: INFORMATICS PRACTICES: SOLUTION OF PRACTICALS  LIST

Practical 1   Solution :
private void grButtonActionPerformed(java.awt.event.ActionEvent evt) {                                        
        float N1, N2, N3; // Variables to hold three input values.
        float max; // Variable to hold maximum value.
        N1 = Integer.parseInt(txtN1.getText());
        N2 = Integer.parseInt(txtN2.getText());
        N3 = Integer.parseInt(txtN3.getText());
        // only checks the nonzero value
        if ((N1 >= 0) && (N2 >= 0) && (N3 >= 0)) {
            max = N1;
            if (N2>max)
                max = N2;
            if (N3>max)
                max = N3;
            jLabel4.setText("The greater number is : " +max);
        }
}                                       

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


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

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        jTextArea1.append("Friend's Data" + "\n");   // Roll No.
        jTextArea1.append("Roll No.: " + jTextField1.getText() + "\n");   // Roll No.
        jTextArea1.append("Name: " + jTextField2.getText() + "\n");   // Name
        jTextArea1.append("Address: " + jTextField3.getText() + "\n");   // Address
        jTextArea1.append("Section: " + jTextField4.getText() + "\n");   // Section
        jTextArea1.append("Grade: " + jTextField5.getText() + "\n");   // Grade
}             

Practical 3 Solutions:
private void btnSalActionPerformed(java.awt.event.ActionEvent evt) {                                      
        String Desig = jComboBox1.getSelectedItem().toString();

        if (Desig.equals("Project Manager")) {
            jTextField1.setText("200000");
        } else if (Desig.equals("Manager")) {
            jTextField1.setText("150000");
        } else if (Desig.equals("Architect")) {
            jTextField1.setText("100000");
        } else if (Desig.equals("Team Leader")) {
            jTextField1.setText("100000");
        } else if (Desig.equals("Sr. Programmer")) {
            jTextField1.setText("75000");
        } else if (Desig.equals("Programmer")) {
            jTextField1.setText("50000");
        } else if (Desig.equals("Operator")) {
            jTextField1.setText("25000");
        }
}                                     

    private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {                                       
        System.exit(0);
}    
Practical 4 Solutions:
private void btnAOActionPerformed(java.awt.event.ActionEvent evt) {                                     
        int n1, n2, aoPlus, aoMult, aoRem, Diff;
        float aoDiv;
        n1 = Integer.parseInt(txtNum1.getText());
        n2 = Integer.parseInt(txtNum2.getText());
        aoPlus = n1 + n2; // integer addition
        Diff = n1 - n2;  // integer subtraction
        aoMult = n1 * n2;  // integer multiplication
        aoDiv = n1 / n2;  // integer division
        aoRem = n1 % n2;
        txtPlus.setText(String.valueOf(aoPlus));
        txtMinus.setText(String.valueOf(Diff));
        txtMult.setText(String.valueOf(aoMult));
        txtDiv.setText(String.valueOf(aoDiv));
        txtMod.setText(String.valueOf(aoRem));
}                                    

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

       Practical 5 Solutions:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        System.exit(0);
}                                        

    private void btnRevActionPerformed(java.awt.event.ActionEvent evt) {                                      
        String str;
        int value, r_digit;
        value = 0;
        while (value <= 0) {
            value = Integer.parseInt(txtNum.getText());
            if (value <= 0) {
                JOptionPane.showMessageDialog(this, "The number must be positive");
                break;
            }
        }
        str = " ";
        while (value != 0) {
            r_digit = value % 10;
            str = str + Integer.toString(r_digit);
            value = value / 10;
        }
        txtRev.setText(str);

   Practical 6 Solutions:
   private void cmdCalcGradeActionPerformed(java.awt.event.ActionEvent evt) {                                            
        float per = Float.valueOf(txtPer.getText());
        String gr="";
        // Medical section
        if (optMed.isSelected()) {
            if (per >= 80)
                gr = "A";
            else
                if (per >= 60 && per <= 78)
                    gr = "B";
                else
                    if (per < 60)
                        gr = "C";
        }
        // Non-Medical section
        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);
}                                           

    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);
}                                       

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

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

    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;  // Total marks
        per = Total/2; // Percentage of marks
        if (chkNCC.isSelected())
            per = per + 3; // Extra 3% is given as NCC Cadet
        // Displaying percentage
        txtPer.setText(Float.toString(per));
                                        
Practical 7 Solutions:
class Report
    {
        int adno;
                String Name;
                float M1, M2, M3, M4, M5;
        float average;
                float getavg( )
                {
            return ((M1 + M2 + M3 + M4 + M5)/5);
        }
        void read_info( )
                {
            adno = Integer.parseInt(txtAdm.getText());
            Name = txtSname.getText();
            M1 = Integer.parseInt(txtM1.getText());
            M2 = Integer.parseInt(txtM2.getText());
            M3 = Integer.parseInt(txtM3.getText());
            M4 = Integer.parseInt(txtM4.getText());
            M5 = Integer.parseInt(txtM5.getText());
            average = getavg();
                }
                void displayinfo()
        {
            txtAvg.setText(Float.toString(average));
            if (average > 40) {
                jLabel5.setText("You are passed");
                jLabel5.setForeground(Color.blue);
            }
            else {
                jLabel5.setText("You are failed");
                jLabel5.setForeground(Color.red);
            }
        }
    }

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

    private void btnAvgActionPerformed(java.awt.event.ActionEvent evt) {                                      
        // Report class object
        Report RP = new Report();
        // Member method accessed through class object
        RP.read_info();
        RP.displayinfo();
}   
                       
Practical 8 Solutions:
import javax.swing.DefaultListModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;

   private void cmdListActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // Creating a String object City
        String City = txtCity.getText();
        // Creating a ListModel object dModel to perform DefaultListModel
        // method operations
        DefaultListModel dModel = (DefaultListModel) jList1.getModel();
        // Method to add elements into jList1 control
        dModel.addElement(City);
        // Sets the data model for jList1 control
        jList1.setModel(dModel);
}                                      

    private void cmdLCActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // Creating a ListModel object dModel to perform DefaultListModel
        // method operations
        DefaultListModel dModel = (DefaultListModel) jList1.getModel();
        // Clears the jList1 through DefaultListModel
        dModel.clear();
}                                    

    private void cmdComboActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // Creating a String object City
        String City = txtCity.getText();
        // Creating a ComboBoxModel object cModel to perform
        // DefaultComboBoxModel method operations
        DefaultComboBoxModel cModel = (DefaultComboBoxModel) jComboBox1.getModel();
        // Method to add elements into jComboBox1 control
        cModel.addElement(City);
        // Sets the data model for jComboBox1 control
        jComboBox1.setModel(cModel);
}                                       

    private void cmdCCActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // Creating a ComboBoxModel object cModel to perform
        // DefaultComboBoxModel method operations
        DefaultComboBoxModel cModel = (DefaultComboBoxModel) jComboBox1.getModel();
        // Clears the jComboBox1 through DefaultComboBoxModel
        cModel.removeAllElements();
}                                    

    private void cmdLCIndActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // Creating a String object City
        String City =  (String) jList1.getSelectedValue();
        int ind = jList1.getSelectedIndex();
        if (jList1.isSelectedIndex(ind)) {
            // Creating a ListModel object dModel to perform DefaultListModel
            // method operations
            DefaultListModel dModel = (DefaultListModel) jList1.getModel();
            // Remove the data at ind position
            dModel.remove(ind);
            // This displays the deleted item in a message box.
            // Add the line, at top of the source code:
            // import javax.swing.JOptionPane;
            JOptionPane.showMessageDialog(this, "Deleted name " + City);
            jList1.setModel(dModel);
        } else
            JOptionPane.showMessageDialog(this, "Note name is selected from list");
        // TODO add your handling code here:
}                                        

    private void cmdClearActionPerformed(java.awt.event.ActionEvent evt) {                                        
        txtCity.setText("");
}                                       

    private void cmdCBIndActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // Creating a String object City
        String City = (String) jComboBox1.getSelectedItem();
        int ind = jComboBox1.getSelectedIndex();
        // Creating a ComboBoxModel object cModel to perform
        // DefaultComboBoxModel method operations
        DefaultComboBoxModel cModel = (DefaultComboBoxModel) jComboBox1.getModel();
        // Remove the data at ind position
        cModel.removeElementAt(ind);
        // This displays the deleted item in a message box.
        // Add the line, at top of the source code: import javax.swing.JOptionPane;
        JOptionPane.showMessageDialog(this, "Deleted name " + City);
        jComboBox1.setModel(cModel);
}    

Practical 9 Solutions:
private void cmdNetActionPerformed(java.awt.event.ActionEvent evt) {                                      
        float NetPrice;
        NetPrice = Float.parseFloat(txtLPrice.getText()) - Float.parseFloat(txtDiscount.getText());
        txtNPrice.setText(Float.toString(NetPrice));
}                                     

    private void cmdListActionPerformed(java.awt.event.ActionEvent evt) {                                       
        String Product = cmbProduct.getSelectedItem().toString();
        if (Product.equals("Washing Machine")) {
            txtLPrice.setText("12000");
        } else if (Product.equals("Color Television")) {
            txtLPrice.setText("17000");
        } else if (Product.equals("Refrigerator")) {
            txtLPrice.setText("18000");
        } else if (Product.equals("OTG")) {
            txtLPrice.setText("8000");
        } else if (Product.equals("CD Player")) {
            txtLPrice.setText("14500");
        }
}                                      

    private void cmdDiscActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // TODO add your handling code here:
        float ProductPrice, Discount;
        ProductPrice = Float.parseFloat(txtLPrice.getText());
        // Calculating Discount Price
        if (optFest.isSelected()) {
            Discount = ProductPrice * 17 /100;
        } else {
            Discount = ProductPrice * 10 /100;
        }
        txtDiscount.setText(Float.toString(Discount));
}                                      

    private void cndExutActionPerformed(java.awt.event.ActionEvent evt) {                                       
        System.exit(0);
}         
           
Practical 10 Solutions:
  private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {                                       
        System.exit(0);
}                                      

    private void txtPrincipalActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
}                                           

    private void cmdCalculateActionPerformed(java.awt.event.ActionEvent evt) {                                            
                // TODO add your handling code here:
        int T = Integer.parseInt(txtTime.getText());
        // Compound interest and total amount
        double CI = 0, Amount =0;
        // Principal amount
        double P = Double.parseDouble(txtPrincipal.getText());
        // Rate of interest
        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;
            }
        // If Sr. Citizen selected
        if (chkSR.isSelected())
            R = R + 2;
        // Displaying Rate
        txtRate.setText(Float.toString(R));
        // pow() function calculates power of a number
        CI = P * Math.pow((1 + (R/100)), T);
        // Calculating total amount
        Amount = P + CI;
        txtInterest.setText(String.valueOf(CI));
        txtAmount.setText(String.valueOf(Amount));

}                                           

    private void cmdClearActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        txtPrincipal.setText("");
        txtTime.setText("");
        txtRate.setText("");
        txtInterest.setText("");
        txtAmount.setText("");
        optFD.setSelected(true);  // Default button selected
        optRD.setSelected(false);  // Default button selected
}           

Practical 11 Solutions:
class Batsman
                                                {
                                                                int bcode;
                                                                String bname;
                                                                int innings, notout, runs;
                                                                float batavg;
                                                                float calcavg()
                                                                {
                                                                                return (runs/(innings-notout));
                                                                }
                                                                void readdata()
                                                                {
                                                                                bcode = Integer.parseInt(txtCode.getText());
                                                                                bname = txtName.getText();
                                                                                innings = Integer.parseInt(txtIn.getText());
                                                                                notout = Integer.parseInt(txtNot.getText());
                                                                                runs = Integer.parseInt(txtRuns.getText());
                                                                                batavg = calcavg();
                                                                }
                                                                void displaydata()
                                                                {
                                                                                txtAvg.setText(Float.toString(batavg));
                                                                }
                                                }
    private void btnAvgActionPerformed(java.awt.event.ActionEvent evt) {                                      
        // Batsman class object
        Batsman BT = new Batsman();
        // Member method accessed through class object
        BT.readdata();
        BT.displaydata();
}                                     

    private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {                                       
        System.exit(0);
}     
  
Practical 13 Solutions:
  private void btnCompActionPerformed(java.awt.event.ActionEvent evt) {                                       

        // Decclare & initialize variables for storing subject marks
        int english = Integer.parseInt(txtEng.getText());
        int maths = Integer.parseInt(txtMaths.getText());
        int science = Integer.parseInt(txtSc.getText());
        int history = Integer.parseInt(txtHist.getText());

        // Compute and set total marks
        int total = english + maths + science + history;
        txtTot.setText("" + total);

        // Compute and get average marks
        int average = total / 4;
        txtAvg.setText("" + average);

        // Compute and set Result and Grade
        if (average >= 75) {
            txtR.setText("Distinction");
            txtG.setText("A");
        } else if (average >= 60) {
            txtR.setText("First Class");
            txtG.setText("B");
        } else if (average >= 50) {
            txtR.setText("Second Class");
            txtG.setText("C");
        } else if (average >= 40) {
            txtR.setText("Average");
            txtG.setText("D");
        } else {
            txtR.setText("Fail");
            txtG.setText("F");
        }
}                                      

    private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {                                       
        System.exit(0);
}                  
     
Practical 14 Solutions:
  private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {                                       
        System.exit(0);
}                                      

    private void btnIncActionPerformed(java.awt.event.ActionEvent evt) {                                      
        // Declare & initialize variables for storing sales
        int sales = 0;

        if (!txtSales.getText().trim().equals("")) {
            sales = Integer.parseInt(txtSales.getText().trim());
        }

        double incentive = 0.0;

        if (jCheckBox1.isSelected()) {
            incentive = incentive + 0.1;    // 10%
        }
        if (jCheckBox2.isSelected()) {
            incentive = incentive + 0.08;    // 8%
        }
        if (jCheckBox3.isSelected()) {
            incentive = incentive + 0.05;   // 5%
        }
        txtInc.setText("" + Math.round(sales * incentive));
}                                     
Practical 15 Solutions:
   private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        System.exit(0);
}                                       

    private void btnStringActionPerformed(java.awt.event.ActionEvent evt) {                                         
        String Name = txtName.getText();
        String School = txtSch.getText();
        String nName = Name.concat(School); // Concatenate Name with School
        int nlength = Name.length();
        String nStr = Name.substring(9);  // Index stats from 9th position
        String nStr1 = School.substring(9, 13); // Index start from 9th position till 13th
        String uCase = Name.toUpperCase(); // Converts into uppercase letters
        String LCase = School.toLowerCase(); // Converts into lowercase letters
        String mess1 = "          My Personal Bio-Data    ";
        String Year = "2014";
        String nTrim = mess1.trim() + " " + Year;
        txtStringArea.append("Concatenated string: " + nName + "\n");
        txtStringArea.append("Length of '" + Name + "' is: " + nlength + "\n");
        txtStringArea.append("Name.substring(9) is: " + nStr + "\n");
        txtStringArea.append("School.substring(9, 13) is: " + nStr1 + "\n");
        txtStringArea.append("Name.toUpperCase() is: " + uCase + "\n");
        txtStringArea.append("School.toLowerCase() is: " + LCase + "\n");
        txtStringArea.append("mess1 trim is: " + nTrim + "\n");


1 comment: