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