## welbyobeng 3

Hey I am a newbie in java and I was wondering if someone can help me. Where would I place

int [] qDifference = new int [3];
for(int i = 0; i < 3; i++)
{
qDifference = q - q;
}

in the code below to show the each division and quarter increase or decrease from the previous quarter

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

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

}

}

## Ezzaral 2,714

After you have computed the quarterly totals and before you display the differences seems like a pretty good candidate.

## welbyobeng 3

Am a newbie and I am trying to display each division and quarter increase or decrease from the previous quarter. I want it to look nice when it is displayed but it seems not to come out right. Can someone help me

``````import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import java.text.DecimalFormat;
public class sales {
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);
output.append("\nDivision differences  ");
double [] dDifference = new double [5];
for(int d = 0; d < 5; d++)
{
dDifference[d] = divtotal[d + 1] - divtotal[d];
output.append(dDifference[d] + "\t");
output.append("\nQuarterly differences  ");
double [] qDifference = new double [3];
for(int i = 0; i < 3; i++)
{
qDifference = qtrtotal - qtrtotal;
}
JOptionPane.showMessageDialog(null,output);

}
}
}
``````