Q.You should use a two dimensional array of 5 columns to represent each day and 4 rows to represent each shop.
Fill in the number of customers every shop had over the week using random numbers between 100 and 500.
The totals should be calculated and displayed beside each row when you output the array.

Ive no problem doing this part of the code but i cant figure out part b

Amend the above program such that the shop with the largest number of customers on a particular day is noted. For example, from the above sample data, the output would be:
Shop 1 – O’Connell Street had the most customers on Tuesday at 499 people
Here's my attempt

im not sure if im even going about this the right way
any help would be greately appricated

March 10th, 2010, 07:08 AM

The Lost Plot

Re: Array help needed

Shop 1 – O’Connell Street had the most customers on Tuesday at 499 people

ok ive got the program to find the most visits per shop per day but im having trouble outputting the part of the line highlighted in red

i think i could use an if/ else if statements but this will make my code very bluky if you know what i mean is there a simpler way to do this

March 10th, 2010, 09:58 AM

Faz

Re: Array help needed

OK the just looking at the code I think you just need to add a few index variables. It's definatly not the most elegant solution as I would have the print statement in the loop(this would need an array with day strings though so up to you). SO declare index(as ints and initialise them in the loop)

EDIT: On second thought you could drop the largest variables and just use the index.

Code :

on Monday with " + shoptotal[index1][0] + " Customers

Once again it's not the most elegant solution as I would use a few nested loops but I don't know if your interested in completely changing your code.

March 10th, 2010, 09:59 AM

helloworld922

Re: Array help needed

If you're just printing out to the console screen, I would strongly recommend against trying to get different colors. The only other color other than the standard black is the red (and actually, this only hold some times) is to use the System.err stream. However, this stream should only be used for Exception handling, and not for standard output.

If you want different colors, create a Swing application and use a JTextPane to format you colors accordingly. Note that you will need some way to distinguish between what should be red and what should be black. The easiest way usually is to keep the two in separate strings. Using if/else statements is the second method.

March 10th, 2010, 10:05 AM

Faz

Re: Array help needed

Quote:

Originally Posted by helloworld922

If you're just printing out to the console screen, I would strongly recommend against trying to get different colors. The only other color other than the standard black is the red (and actually, this only hold some times) is to use the System.err stream. However, this stream should only be used for Exception handling, and not for standard output.

If you want different colors, create a Swing application and use a JTextPane to format you colors accordingly. Note that you will need some way to distinguish between what should be red and what should be black. The easiest way usually is to keep the two in separate strings. Using if/else statements is the second method.

I don't think he wanted to print it in red, I think he just meant that he didn't know how to print it at all. The highlighting was done to show us what he couldn't do.

I think.

March 12th, 2010, 11:22 AM

The Lost Plot

Re: Array help needed

yeah the part in red was to show the bit of the output i was stuck on,i ended up declaring a second arary for the days and finding the highest total of visits for the week and not per day.