Problem in Java “change in the status of a cell.”

Asked By 5 points N/A Posted on -
qa-featured

Hello,
I have a small question about OOP. Let me explain:
I have a Grid object:
Code :

    1.import java.util.*;
    2.import java.io.*;
    3.import java.lang.Math;
    4.public class Grid {
    5.private static Cell[][] grid;
    6.private int sizeOfGrid;
    7.public Grid(int size) { // Déclaration d'un tableau de cellules
    8.sizeOfGrid = size;
    9.grid = new Cell[size][size];
   10.}

The grid object is an array of subject Cell:
Code :

    1.public class Cell {
    2.private CellStatus status;
    3.private int aliveNeighbour;
    4.public Cell() {
    5.status.makeCellDead();
    6.aliveNeighbour = 0;
    7.}

and finally, the class Cell contains an object CellStatus:

 
Code :

    1.public class CellStatus {
    2.private boolean alive;
    3.public CellStatus (boolean isAlive) {
    4.alive = isAlive;
    5.}

The Boolean object alive CellStatus can see if a cell is alive or dead. In the program, I have to change the status of a cell.

For example: grid [x] [y]. MakeCellDead ();

I wonder how I do it. If the variables must be static, etc …

thank you

SHARE
Answered By 0 points N/A #84048

Problem in Java “change in the status of a cell.”

qa-featured

Hey,

 

If you want to get the status of the cell in JAVA there is a function getStateCell(int col, int row) which gets the status of the cell. The cell has two status dead or alive. You need to provide the column number and row number.

If you want to set the status of the cell in JAVA there is a function setCell(int col, int row, State state) which sets the status of the cell. You need to provide the column number, row number and the status you want to set for the cell i.e. alive or dead.

Thanks.

Related Questions