I have just finished a java code and I am having trouble with displaying each division increase or decrease from previous quarter and also a company increase or decrease from the previous quarter.

Can someone help

import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import java.text.DecimalFormat;
public class twoarray {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // Declare Variables
        double[][] sales= new double[6][4];
        double [] divtotal = new double[6];
        double [] qtrtotal = new double [4];
        double mindiv = Double.MAX_VALUE, minqtr = Double.MAX_VALUE;
        double maxdiv = Double.MIN_VALUE, maxqtr = Double.MIN_VALUE;
        double overallTotal = 0.0;
        String input;
        JTextArea output = new JTextArea();
        DecimalFormat twodigit = new DecimalFormat("0.00");
        // Get Input Data in Row wise order
        output.setText("Div\tQtr1\tQtr2\tQtr3\tQtr4\tTotal\tAverage\n");
        for(int div = 0; div < 6; div++){
            for(int qtr =0; qtr < 4; qtr++){
                input = 
                        JOptionPane.showInputDialog
                            ("Division " + (div + 1) 
                                    + ", Quarter " + (qtr + 1) 
                                    + ": $");
                sales [div][qtr] = Double.parseDouble(input);
                //output.append(sales[div][qtr]+ "\t");
            }
            //output.append("\n");
        }
        //JOptionPane.showMessageDialog(null,output);
        // Sum Division Totals by Row
        // Find min and max division

        for(int div = 0; div < 6; div++){
            output.append((div + 1) + "\t");
            for(int qtr =0; qtr < 4; qtr++){
                divtotal[div]+= sales[div][qtr];
                output.append(sales[div][qtr]+ "\t");
            }
            if(divtotal[div] > maxdiv)
                maxdiv = divtotal[div];
            if(divtotal[div] < mindiv)
                mindiv = divtotal[div];
            output.append( divtotal[div] + "\t " +
                    + (divtotal[div] /4.0) + "\n");
        }
        // Get Column totals
        output.append("\t");
        for(int qtr = 0; qtr < 4; qtr++){
            for(int div=0; div < 6; div++){
                qtrtotal[qtr] += sales[div][qtr]; 
                overallTotal += sales[div][qtr];

            }
            if(qtrtotal[qtr] > maxqtr)
                maxqtr = qtrtotal[qtr];
            if(qtrtotal[qtr] < minqtr)
                minqtr = qtrtotal[qtr];
            output.append(qtrtotal[qtr] + "\t");
        }
        output.append(overallTotal + "\t");
        output.append("\nMin Div Total = " + mindiv
                + " Max Div Total = " + maxdiv);
        output.append("\nMin Qtr Total =" + minqtr +
                " Max Qtr Total = "+ maxqtr);
        JOptionPane.showMessageDialog(null,output);







    }

}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

I don't see any code to make those calculations, so I guess that is "trouble" you are having?

Yes Ezzaral, I dont even know how to go about it...please help

Well, you have all of the data - just make the calculation. For each division you have each quarters numbers, so that is a simple subtraction of one quarter total from another. The same is true for the company after you have finished the "qtrtotal" array calcs.

Well, you have all of the data - just make the calculation. For each division you have each quarters numbers, so that is a simple subtraction of one quarter total from another. The same is true for the company after you have finished the "qtrtotal" array calcs.

I understand...that is where i am suffering at...Can you provide me the code...I am new at java trying to learn it. I am newbie

int qDifference = q[1] - q[0];

or even more explicitly

int qDifference = q[index] - q[index-1];

I really don't see how I could give you any more than that without writing it directly in your program (which, before you ask, I will not do).

This article has been dead for over six months. Start a new discussion instead.