Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: How do I get the one part of the needed output for quarterly sales-statistics?

1. ## Re: How do I get the one part of the needed output for quarterly sales-statistics?

Have you looked at the printed output to see why the missing line is not being printed?

There is data for 4 quarters, why doesn't the data for one of the quarters get printed?

Look at the if statement that controls the printing. What values are required for the if statement to be true? How do the variables in the if statemennt get the correct values for the if to be true?

2. ## Re: How do I get the one part of the needed output for quarterly sales-statistics?

I answered each question one at a time.

Have you looked at the printed output to see why the missing line is not being printed?
I have, and I believe it has to do with the way I declared highestQuart - as an accumulator, somehow - so I need help with that. Now I think I may have to make an if-statement for all of the quarters.

There is data for 4 quarters, why doesn't the data for one of the quarters get printed?
I think data did not get printed for 4 quarters because there were always fewer numbers for it to print when it accumulated.

Look at the if statement that controls the printing. What values are required for the if statement to be true?
It goes like this: If the last highest-quarter's number is equal to the current division's sales-figure then say, "Inside if-statement, quarters = # & divisions = #," so the values are highestQuart and salesFigures[quarters][divisions].

How do the variables in the if-statement get the correct values for the if to be true?
The highestQuarter-variable was supposed to be replaced by another value, if you know what I mean, each time the second nested-for-loop passed for each quarter. As for the other variable, with each passing-loop, each quarter (all of them, 0-3) stays the same for six divisions (0-5) while each division-number is recieved by the second element-variable.

3. ## Re: How do I get the one part of the needed output for quarterly sales-statistics?

I think data did not get printed for 4 quarters because there were always fewer numbers for it to print when it accumulated.
What does that mean? Each quarter has a highest sales figure amongst all the divisions. Why don't they all print?

Look at the data you printed out again. Why are you comparing the highest value from one quarter with the values for the next quarter? Should the values for each quarter be compared against only the other values for that same quarter and not against the values from preceding quarters?

4. ## The Following User Says Thank You to Norm For This Useful Post:

SOG (June 27th, 2012)

5. ## Re: How do I get the one part of the needed output for quarterly sales-statistics?

What does that mean? Each quarter has a highest sales figure amongst all the divisions. Why don't they all print?
I thought I made the highestQuart-variable an accumulator and now I realize that it does work as a non-accumulator, but I believe they don't all print because 3 more variables are needed to store the sales-figures in.

Look at the data you printed out again. Why are you comparing the highest value from one quarter with the values for the next quarter? Should the values for each quarter be compared against only the other values for that same quarter and not against the values from preceding quarters?
As I did say before in this part of the thread, I believe I need 3 more variables to compare sales-figures to their associated ones within each quarter. By the way, I do believe each quarter should be compared against only others from the same quarter - not with ones from different quarters.

6. ## Re: How do I get the one part of the needed output for quarterly sales-statistics?

I solved the problem with something else to consider: one different array variable, and one new loop-control variable Here is how it works in code...

```                // Use these nested-loops to display the highest sales-division for a quarter.
for (int quarters = 0; quarters < QUARTERS; quarters++)
{
allDivisions++;

for (int divisions = 0; divisions < DIVISIONS; divisions++)
{
if (salesFigures[quarters][divisions] > highestQuart[allDivisions])
{
highestQuart[allDivisions] = salesFigures[quarters][divisions];
}
}

for (int divisions = 0; divisions < DIVISIONS; divisions++)
{
if (salesFigures[quarters][divisions] == highestQuart[allDivisions])
{
System.out.println("Inside if-statement, quarters = " + quarters + " & divisions = " + divisions);
}
}
}```

...and this is what the computer's output was...

```
Inside if-statement, quarters = 0 & divisions = 2
Inside if-statement, quarters = 1 & divisions = 0
Inside if-statement, quarters = 1 & divisions = 4
Inside if-statement, quarters = 2 & divisions = 1
Inside if-statement, quarters = 3 & divisions = 2
```

...so as you can see, the computer gave all of the answers needed - even if some were equivalent. Now I only have to type up this kind of statement...

`System.out.println("Highest sales-division for Quarter-" + (quarters + 1) + ": " + (divisions + 1));`

...to get this kind of output.

```
Highest sales-division for Quarter-1: 1
Highest sales-division for Quarter-2: 5
Highest sales-division for Quarter-3: 6
Highest sales-division for Quarter-4: 4
```

7. ## Re: How do I get the one part of the needed output for quarterly sales-statistics?

Is the output correct now?
What if there are two divisions with the same sales? Have you tested that?

8. ## Re: How do I get the one part of the needed output for quarterly sales-statistics?

Is the output correct now?
What if there are two divisions with the same sales? Have you tested that?
Yes, the output is correct, I have tested the second part too, and more than one division has appeared in a quarter. I somehow believe this works because of the way I setup the new array-variable - with 24 divisions for 4 quarters of 6 divisions, and 6 times 4 does equals 24.

9. ## Re: How do I get the one part of the needed output for quarterly sales-statistics?

A comment on your fix. The new code with the highestQuart array resets the value of highestQuart to zero every time the index to the array (allDivisoins) is incremented. 0 is the default contents of an int array.
A simpler solution would be to use the old version without the array and just set highestQuart to 0 when starting the search for the next division's highest value.

Page 2 of 2 First 12