Results 1 to 4 of 4
Thread: Help with arrays and matrices!
 02072013, 12:46 AM #1Member
 Join Date
 Feb 2013
 Posts
 4
 Rep Power
 0
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.
Thanks in advance!
Java 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 + " "); } } } } }
 02112013, 02:59 PM #2Senior Member
 Join Date
 Oct 2010
 Posts
 393
 Rep Power
 10
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.
 02132013, 06:54 AM #3Member
 Join Date
 Feb 2013
 Posts
 4
 Rep Power
 0
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!
 02132013, 12:46 PM #4Senior Member
 Join Date
 Oct 2010
 Posts
 393
 Rep Power
 10
Similar Threads

Arrays and Matrices
By Shaeman111 in forum New To JavaReplies: 2Last Post: 11102012, 08:24 AM 
how to add columns from Matrices(2D array)
By John_shok in forum New To JavaReplies: 7Last Post: 10042010, 05:33 PM 
Read two matrices from file
By zenitis in forum New To JavaReplies: 13Last Post: 05202010, 04:03 AM 
How to multiply two matrices
By Java Tip in forum java.langReplies: 0Last Post: 04142008, 09:50 PM 
implementing sparse and nonsparse matrices together
By ishakteyran in forum New To JavaReplies: 0Last Post: 12072007, 09:10 PM
Bookmarks