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


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 33 of 33

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

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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?
    Last edited by Norm; June 27th, 2012 at 04:39 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Member
    Join Date
    Jul 2011
    Posts
    62
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default 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.
    Last edited by SOG; June 27th, 2012 at 05:47 PM.

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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?
    If you don't understand my answer, don't ignore it, ask a question.

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

    SOG (June 27th, 2012)

  5. #29
    Member
    Join Date
    Jul 2011
    Posts
    62
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default 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. #30
    Member
    Join Date
    Jul 2011
    Posts
    62
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default 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


    Last edited by SOG; June 27th, 2012 at 11:25 PM.

  7. #31
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #32
    Member
    Join Date
    Jul 2011
    Posts
    62
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default 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. #33
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Total Sales Error
    By KRUKUSA in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 19th, 2012, 08:20 PM
  2. Sales not working
    By JeremiahWalker in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 9th, 2012, 10:07 AM
  3. [SOLVED] Need statistics Homework help?
    By keith thomas in forum Java Theory & Questions
    Replies: 1
    Last Post: January 7th, 2011, 02:20 AM
  4. Black Jack Statistics game? lost.
    By mindlessn00b in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 20th, 2010, 07:20 AM
  5. How to save statistics of a game in a binary file instead of txt file?
    By FretDancer69 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: June 19th, 2009, 05:05 AM

Tags for this Thread