1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

2D array

Discussion in 'Java' started by Crooksy, Sep 21, 2006.

  1. Crooksy

    Crooksy New Member

    Joined:
    Sep 20, 2006
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hello,

    Could someone help me out, I am very new to programming( as one could tell by the Question I am about to ask.)

    I am trying to assign a value to random spots in a 2D array. This is what I have so far:
    Code:
    [COLOR=Blue]
       /** 
         * Generates random coordinates, puts them into a new CoordinatePair,
         * returns CoordinatePair - This method is complete and requires no change.
         * @return a randomly-generated pair of coordinates within the bounds of the
         * grid
         */[/COLOR]
        private CoordinatePair getRandomCoordinates()
        {
            CoordinatePair coords = new CoordinatePair();  // create a new coordinate pair object
            coords.setRow(random.nextInt(ROWS));           // randomly select a row, put row info into object
            coords.setColumn(random.nextInt(COLUMNS));     // randomly select a column, put column info into object
            return coords;                                 // return the object
        }
        
       [COLOR=Blue] /**
         * Invokes getRandomCoordinates() to put a specific value into the number of
         * grid positions specified by the first parameter, e.g. 
         * setRandomCoordinates(5, 'T') will set the target char 'T' into 5 different
         * locations in the grid on which it is invoked. This method will be invoked on the 
         * working grid.
         * @param the number of randomly-generated coordinates to set with the value,
         * the target value to set
         */
     [/COLOR]   
    This is where I need help, setting up this next method:

    public void setRandomCoordinates(int numCoordsToSet, char valueToSet)
     
    Last edited by a moderator: Sep 21, 2006
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Isnt the set method just simple value putting into the class member variable. Can you put the class which has this function as set should just assign the value.
     

Share This Page