Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

As the newest systems analyst at AgriFeed Corporation, a company in the Midwest

ID: 657781 • Letter: A

Question

As the newest systems analyst at AgriFeed Corporation, a company in the Midwest that specializes in high technology feed grains for livestock, your boss calls you into the office. He explains that the R & D (Research and Development) Department needs a way to calculate simple statistical values for data gathered from testing on their mobile tablets while out on the field. Since the researchers use low-powered devices with 6-inch screens only capable of 480x360 pixels, they are not able to run most sophisticated statistics packages; however, they are capable of running simple Java applications. Your boss sends you to the end users to gather their general requirements. Here

Explanation / Answer

Program:

package Analysis;

public class AnalysisUI extends javax.swing.JFrame {

    public AnalysisUI() {

        initComponents();

    }

  

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         

    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();

        jLabel2 = new javax.swing.JLabel();

        jLabel3 = new javax.swing.JLabel();

        jScrollPane2 = new javax.swing.JScrollPane();

        jList1 = new javax.swing.JList();

        jButton1 = new javax.swing.JButton();

        jTextField1 = new javax.swing.JTextField();

        jButton2 = new javax.swing.JButton();

        jTextField2 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Enter 10 Soil Moisture Values with space in between:");

        jLabel2.setBackground(new java.awt.Color(204, 255, 204));

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N

        jLabel2.setForeground(new java.awt.Color(255, 102, 102));

        jLabel2.setText("STATISTICAL ANALYSIS PACKAGE");

        jLabel3.setText("Possible tests:");

        jList1.setModel(new javax.swing.AbstractListModel() {

            String[] strings = { "Sum of SoilMoisture", "Maximum value", "Minimum value", "Mean value", "Standard deviation", " " };

            public int getSize() { return strings.length; }

            public Object getElementAt(int i) { return strings[i]; }

        });

        jScrollPane2.setViewportView(jList1);

        jButton1.setBackground(new java.awt.Color(153, 255, 255));

        jButton1.setForeground(new java.awt.Color(0, 0, 255));

        jButton1.setText("Run Test");

        jButton1.setName("RunTest"); // NOI18N

        jButton1.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                jButton1ActionPerformed(evt);

            }

        });

        jButton2.setBackground(new java.awt.Color(153, 255, 255));

        jButton2.setForeground(new java.awt.Color(0, 0, 255));

        jButton2.setText("Clear");

        jButton2.setName("Clear"); // NOI18N

        jButton2.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                jButton2ActionPerformed(evt);

            }

        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

        getContentPane().setLayout(layout);

        layout.setHorizontalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addContainerGap()

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()

                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                            .addComponent(jLabel3)

                            .addComponent(jLabel1))

                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                            .addGroup(layout.createSequentialGroup()

                                .addGap(52, 52, 52)

                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))

                            .addGroup(layout.createSequentialGroup()

                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

                                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE))))

                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()

                        .addGap(69, 69, 69)

                        .addComponent(jLabel2))

                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()

                        .addGap(12, 12, 12)

                        .addComponent(jButton2)

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                        .addComponent(jButton1)

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 379, javax.swing.GroupLayout.PREFERRED_SIZE)))

                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

        );

        layout.setVerticalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(layout.createSequentialGroup()

                .addComponent(jLabel2)

                .addGap(35, 35, 35)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

                .addGap(67, 67, 67)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(jLabel3))

                .addGap(31, 31, 31)

                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(jButton1)

                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(jButton2))

                .addContainerGap(36, Short.MAX_VALUE))

        );

        pack();

    }// </editor-fold>                       

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

        // Run test Button

        int sum,max, min;

        float avg;

        double std;

        String text;

        int soilMoisture[]=new int[11];

        String t=jTextField2.getText();

        String s[]=t.split(" ");

        for(int i=0;i<10;i++)

            soilMoisture[i]= Integer.parseInt(s[i]);

        switch (jList1.getSelectedIndex()) {

            case 1: sum=getSum(soilMoisture);

                     text=(String) jList1.getSelectedValue()+": "+sum;

                     jTextField1.setText(text);

                     break;

            case 2: min=getMin(soilMoisture);

                     text=(String) jList1.getSelectedValue()+": "+min;

                     jTextField1.setText(text);

                     break;

            case 3: max=getMax(soilMoisture);

                     text=(String) jList1.getSelectedValue()+": "+max;

                     jTextField1.setText(text);

                     break;

                   

            case 4: sum=getSum(soilMoisture);

                     avg=sum/10;

                     text=(String) jList1.getSelectedValue()+": "+avg;

                     jTextField1.setText(text);

                     break;

                    

            case 5: std= getStd(soilMoisture);

                    

                     text=(String) jList1.getSelectedValue()+": "+std;

                     jTextField1.setText(text);

                     break;

        }

    }                                       

    private int getSum(int soilMoisture[] )

    {

        int i;

//sum

    int sum=0;

    for(i=0;i<10;i++)

        sum+= soilMoisture[i];

    return sum;

    }

   

   private int getMin(int soilMoisture[] )

    {

        int min=soilMoisture[0];

for(int i=0;i<10;i++)

{

if(soilMoisture[i]<min)

min= soilMoisture[i];

}

    return min;

}

     private int getMax(int soilMoisture[] )

    {

        int max=soilMoisture[0];

for(int i=0;i<10;i++)

{

if(soilMoisture[i]<max)

max= soilMoisture[i];

}

    return max;

}

     private double getStd(int soilMoisture[] )

    {

     float avg=getSum(soilMoisture)/10;

     int sum1=0;

for(int i=0;i<10;i++)

sum1+= Math.pow((soilMoisture[i]-avg),2);

sum1/= 9;

        double std=Math.sqrt(sum1);

    return std;

}

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

            // Clear button

        jTextField1.setText(null);

        jTextField2.setText(null);

       

    }                                       

    /**

     * @param args the command line arguments

     */

    public static void main(String args[]) {

        /* Set the Nimbus look and feel */

        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">

        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

         */

        try {

            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {

                if ("Nimbus".equals(info.getName())) {

                    javax.swing.UIManager.setLookAndFeel(info.getClassName());

                    break;

                }

            }

        } catch (ClassNotFoundException ex) {

            java.util.logging.Logger.getLogger(AnalysisUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (InstantiationException ex) {

            java.util.logging.Logger.getLogger(AnalysisUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (IllegalAccessException ex) {

            java.util.logging.Logger.getLogger(AnalysisUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (javax.swing.UnsupportedLookAndFeelException ex) {

            java.util.logging.Logger.getLogger(AnalysisUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        }

        //</editor-fold>

        /* Create and display the form */

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {

                new AnalysisUI().setVisible(true);

            }

        });

    }

    // Variables declaration - do not modify                    

    private javax.swing.JButton jButton1;

    private javax.swing.JButton jButton2;

    private javax.swing.JLabel jLabel1;

    private javax.swing.JLabel jLabel2;

    private javax.swing.JLabel jLabel3;

    private javax.swing.JList jList1;

    private javax.swing.JScrollPane jScrollPane2;

    private javax.swing.JTextField jTextField1;

    private javax.swing.JTextField jTextField2;

    // End of variables declaration                  

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote