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

Almost forgot - here's the output so far.

Please answer the following questions and this program will perform multiple calculations for you.
Enter sales for Division 1, Quarter 1: \$
20
Enter sales for Division 1, Quarter 2: \$
20
Enter sales for Division 1, Quarter 3: \$
20
Enter sales for Division 1, Quarter 4: \$
20

Enter sales for Division 2, Quarter 1: \$
20
Enter sales for Division 2, Quarter 2: \$
20
Enter sales for Division 2, Quarter 3: \$
20
Enter sales for Division 2, Quarter 4: \$
20

YOU ENTERED SALES AS:

DIVISION 1
------------------------------------
Quarter 1: \$20.00
Quarter 2: \$20.00
Quarter 3: \$20.00
Quarter 4: \$20.00

DIVISION 2
------------------------------------
Quarter 1: \$20.00
Quarter 2: \$20.00
Quarter 3: \$20.00
Quarter 4: \$20.00

The total sales by division are \$ 160.00
The total sales for the company are \$ 160.00

A little help
put the 57 line in place of 54 line
Look at results.

Thank you. It's closer. I appreciate the tidbit! Here's what i got - if you're curious.....
YOU ENTERED SALES AS:

DIVISION 1
------------------------------------
Quarter 1: \$20.00
Quarter 2: \$20.00
Quarter 3: \$20.00
Quarter 4: \$20.00
The total sales by division are \$ 80.00

DIVISION 2
------------------------------------
Quarter 1: \$20.00
Quarter 2: \$20.00
Quarter 3: \$20.00
Quarter 4: \$20.00
The total sales by division are \$ 160.00

The total sales for the company are \$ 160.00

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.