2D array

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

  1. Crooksy

    Crooksy New Member

    Sep 20, 2006
    Likes Received:
    Trophy Points:

    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:
         * 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
        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
    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

    Jul 12, 2004
    Likes Received:
    Trophy Points:
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice