Results 1 to 4 of 4
  1. #1
    chwex is offline Member
    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

    Default 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 + " ");
                   }
               }
           }
           
            
        }
    
    }

  2. #2
    Ronin is online now Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    5

    Default 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.

  3. #3
    chwex is offline Member
    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

    Default 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!

  4. #4
    Ronin is online now Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    5

Similar Threads

  1. Arrays and Matrices
    By Shaeman111 in forum New To Java
    Replies: 2
    Last Post: 11-10-2012, 07:24 AM
  2. how to add columns from Matrices(2D array)
    By John_shok in forum New To Java
    Replies: 7
    Last Post: 10-04-2010, 04:33 PM
  3. Read two matrices from file
    By zenitis in forum New To Java
    Replies: 13
    Last Post: 05-20-2010, 03:03 AM
  4. How to multiply two matrices
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:50 PM
  5. implementing sparse and nonsparse matrices together
    By ishakteyran in forum New To Java
    Replies: 0
    Last Post: 12-07-2007, 08:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •