Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) /** * Write the constructor so it takes two integer arguments to represent *

ID: 3537430 • Letter: 1

Question

1)


/**

* Write the constructor so it takes two integer arguments to represent

* the number of rows and columns in the game of life. The constructor

* creates a society with no cells but space to store rows*cols cells.

*

* @param rows The height of the grid that shows the cells.

* @param cols The width of the grid that shows the cells.

*/


public GameOfLife(int rows, int cols) {


}



2)


/**

* Return the number of rows, which can be indexed from 0..numberOfRows()-1.

*

* @return The height of the society.

*/



public int numberOfRows() {

return 0;

}







3)


/**

* The number of columns, which can be indexed from 0..numberOfColumns()-1.

*

* @return The height of the society.

*/



public int numberOfColumns() {

return 0;

}






4)


/**

* Place a new cell in the society.

* Precondition: row and col are in range.

*

* @param row The row to grow the cell.

* @param col The column to grow the cell.

*/



public void growCellAt(int row, int col) {

}



Any idea of how to solve this(using for loops) ???

Explanation / Answer

/**

* Write the constructor so it takes two integer arguments to represent

* the number of rows and columns in the game of life. The constructor

* creates a society with no cells but space to store rows*cols cells.

*

* @param rows The height of the grid that shows the cells.

* @param cols The width of the grid that shows the cells.

*/

private int society[][];

private int r;

private int c;

public GameOfLife(int rows, int cols) {

society[] = new int[rows][cols];

r=rows;

c=cols;


}



/**

* Return the number of rows, which can be indexed from 0..numberOfRows()-1.

*

* @return The height of the society.

*/



public int numberOfRows() {

return r;

}




/**

* The number of columns, which can be indexed from 0..numberOfColumns()-1.

*

* @return The height of the society.

*/



public int numberOfColumns() {

return c;

}



/**

* Place a new cell in the society.

* Precondition: row and col are in range.

*

* @param row The row to grow the cell.

* @param col The column to grow the cell.

*/



public void growCellAt(int row, int col) {

society[row][col]=1;

}


/* 1 represents cell, 0 represents empty */