Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   2D array (http://www.go4expert.com/forums/2d-array-t1445/)

Crooksy 21Sep2006 08:13

2D array

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

shabbir 21Sep2006 11:01

Re: 2D array
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.

All times are GMT +5.5. The time now is 14:08.