Hi - I am a newbie - so I hate to ask for help, but your site has been so useful even before I joined, so I hope you will have pity on me. I am doing a java program using 2D arrays. It covers 4 quarters of sales across 6 divisions of a company.....with the sales being user entered. I am supposed to make a list of the sales entered, the increase/decrease by qtr per div, total for quarter among all divs, total company increase/decrease, avg sales per div, and highest sales per qtr , and whole company all qtrs..... I am fine doing the whole company stuff, but seperating the divisions is proving to be a challenge. My code is below. I haven't gotten all of the whole company stuff yet, but you can see where I am.... The totalDivSales, and divSales variables are my attempt at seperating the divisions - please help if you can. Thanks!
import java.util.Scanner;
import java.text.DecimalFormat;
public class QtrSalesArray
{
public static void main(String[] args)
{
final int DIVS = 2;
final int QTRS = 4;
double totalSales = 0.0;
double totalDivSales = 0.0;
double [][] sales = new double [DIVS][QTRS];
Scanner keyboard = new Scanner(System.in);
System.out.println("Please answer the following questions and this program will perform multiple calculations for you.");
for (int div=0;div<DIVS; div++)
{
for (int qtr=0;qtr<QTRS; qtr++)
{
System.out.println("Enter sales for Division "+ (div+1) + ", Quarter "+ (qtr+1)+": $");
sales[div][qtr] = keyboard.nextDouble();
}
System.out.println();
}
for (int div=0; div<DIVS; div++)
{
for (int qtr=0;qtr<QTRS; qtr++)
{
totalSales+=sales[div][qtr];
}
}
DecimalFormat dollar = new DecimalFormat("#,##0.00");
System.out.println("YOU ENTERED SALES AS:\n");
for (int div=0;div<DIVS; div++)
{
System.out.println("DIVISION "+ (div+1));
System.out.println("------------------------------------");
for (int qtr=0;qtr<QTRS; qtr++)
{
System.out.println("Quarter "+ (qtr+1)+":\t$" +dollar.format(sales[div][qtr]));
totalDivSales+=sales[div][qtr];
}
System.out.println();
}
System.out.println("The total sales by division are $ " + dollar.format(totalDivSales));
System.out.println("The total sales for the company are $ " + dollar.format(totalSales));
}
}