// The quarterStats-program should be able to let the user
// enter four sales-figures for 6 divisions of a company.
// (For 4 quarters in a stock-market year.)
// FOR HELP NEEDED, I SELECTED THE LINES THAT HAVE
// SHOWN UP ERRONEOUS ON THE COMPILER.
// Use this Scanner-class import-statement for input and output.
import java.util.Scanner;
// Use this DecimalFormat-class import-statement for numerical-setups.
import java.text.DecimalFormat;
public class QuarterStats
{
// Use the following variable-setup
// for these matched-up purposes:
final int QUARTERS = 4; // the rows of each sales-quarter,
final int DIVISIONS = 6; // the columns of all 6 divisions,
// the sales-figure array that will hold all of the figures,
double[][] salesFigures = new double[QUARTERS][DIVISIONS];
// the general-figure variable for each entry,
double figure,
// the variable for the highest sales-division for each quarter,
highestQuart = salesFigures[0][0],
// the increase or decrease of sales statistics,
divInOrDecrease,
// an average-sales variable,
avSales,
// the accumulator for the average,
total;
// a Scanner-class object named keys,
Scanner keys = new Scanner(System.in);
// and a DecimalFormat-object named numSetup.
DecimalFormat numSetup = new DecimalFormat("#,##0.00");
// Now get all of the entries.
for (int rows = 0; rows < QUARTERS; rows++)
{
for (int cols = 0; cols < DIVISIONS; cols++)
{
System.out.println("What is division-" + cols + 1 + "\'s quarter-" + rows + 1 + " sales-figure?");
figure = keys.nextDouble();
salesFigures[rows][cols] = figure;
}
}
// Finally, display data for each matched-up purpose.
for (int row = 0; row < QUARTERS; row++)
{
total = salesFigures[row][col] + lastQuarter; // Use the accumulator for an average.
// Use decision-structure to show division's increase or decrease
// from the previous quarter.
if (lastQuarter > salesFigures[row][col + 1])
{
divInOrDecrease = lastQuarter + salesFigures[row][col + 1];
}
else if (lastQuarter < salesFigures[row][col + 1])
{
divInOrDecrease = lastQuarter + salesFigures[row][col + 1];
}
else if (lastQuarter == 0)
{
lastQuarter += salesFigures[row][col + 1];
}
// Display all of the quarter's sales-figures.
System.out.println("Division-" + col + 1 + " sales-figures:");
for (int col = 0; col < DIVSIONS; col++)
{
System.out.println("Q" + rows + 1 + ": " + salesFigures[row][col]);
lastQuarter = salesFigures[row][col];
}
avSale = total / 6; // Get the average.
System.out.println("Quarter-1\'s average sales: " + numSetup.format(avSale));
}
for (int ro = 0; ro < QUARTERS; ro++)
{
for (int clmn = 0; clmn < DIVSIONS; clmn++)
{
if (salesFigures[ro][clmn] > highestQuart)
highestQuart = salesFigures[ro][clmn];
}
// Display the highest division's sales for a quarter.
System.out.println("Highest division's sales for Quarter-" + ro + 1 + ": " + numSetup.format(highestQuart));
}
}