# Help with arrays and matrices!

• 02-07-2013, 12:46 AM
chwex
Help with arrays and matrices!
I am currently stuck with this problem...

Write a program for the next problem. A store sells the following products: Milk, soap, meat, beans and tomatoes. The cost of each product is \$12.5, \$18.2, \$69.9, \$30.5 y \$15.9 respectively. The price for the costumers is 30% more than the cost of the product.

Randomly create numbers from 0 to 10 which will represent the quantity sold of each product each day for a whole month.
The owner wants to know the total sales for each product in a day and the whole month, the total sales of each day and which product gives the most profit for the month.

So far I have created an array that holds the string names, the cost of each product and the price for each costumer. I got stuck on the matrix part where I need to place a vector inside each element... After that I need to start doing the operations inside the matrix such as, accumulators and counters... I started this without guidance, so I don't know if I have the right approach. So far this is what I have.

Code:

```public static void main(String[] args) {       int x=0, y=0, z=0, number=0;       Double precio[];       String[] productos = {"leche", "jabon", "carne", "frijol", "tomate"};       Double[] costo = {12.5, 12.2, 69.9, 30.5, 15.9};       precio = new Double[5];       Random num = new Random();       int mmes[][] = new int [5][6];                   for(x=0; x<=4; x++){           precio[x] = costo[x]+(costo[x]*.30);                     System.out.println(precio[x]);       }             for(x=0; x<=5; x++){           for(y=0; y<=6; y++){                           mmes[x][y] = precio[z];               for(int counter=1; counter>=10; counter++){                   number = num.nextInt(11);                   System.out.println(number + " ");               }           }       }                   } }```
• 02-11-2013, 02:59 PM
Ronin
Re: Help with arrays and matrices!
Hi chwex,

I'm assuming you want something basic for this problem.
You could use a two dimensional array which holds the number of each product sold where each row represents a different item whilst each colums represent a day.
In effect you would use a 5 by 30/31 array to hold the values. The months can get a bit messy though as the actual number of columns required is dependant on the number of days in the month.

Regards.
• 02-13-2013, 06:54 AM
chwex
Re: Help with arrays and matrices!
Thanks for the response Ronin! I appreciate it! I will try your approach since it seems a bit easier than the one I had in mind!
• 02-13-2013, 12:46 PM
Ronin
Re: Help with arrays and matrices!
You're welcome.