> For the complete documentation index, see [llms.txt](https://nissan-goldberg.gitbook.io/java101/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nissan-goldberg.gitbook.io/java101/exercises/exercise-2.md).

# Exercise 2

### &#x20;משחק החיים

{% tabs %}
{% tab title="GameOfLife.java" %}

```java
public class GameOfLife {

    public static void main(String[] args) {
        gameOfLife(240,10);
    }

    //YOU CAN ADD MORE FUNCTIONS IF YOU WANT

    public static void gameOfLife(int n, int cellSize){
        //n = 240; cellSize = 10;
        //TODO
    }
    public static void clearCells(boolean[][]cells) {
        //TODO
    }


    public static void drawCells(boolean[][]cells, int cellSize, Color color) {
        StdDraw.setPenColor(color);
        for (int i=0; i<cells.length; i++) {
            for(int j=0; j<cells[0].length; j++) {
                if (cells[i][j]) {
                    double p = (i*cellSize*2 + cellSize)/2;
                    double q = (j*cellSize*2 + cellSize)/2;
                    StdDraw.filledSquare(p, q, cellSize/2);
                }
            }
        }
    }
}
```

{% endtab %}

{% tab title="NextGeneration.java" %}

```java
public class NextGeneration {
    /* חובה */    
    public static boolean[][] nextGeneration(boolean[][] cells){
        //TODO
    }
    
    
    
    /* לא חובה */    
    public static boolean isInside(boolean[][] cells, int x, int y){ }

    /* לא חובה */   
    public static boolean checkCell(boolean[][] cells, int x, int y){ }

    /* לא חובה */    
    public static int numberOfNeighbors(boolean[][] cells,int x,int y){ }
}
```

{% endtab %}
{% endtabs %}

### Functions that can help

```java
StdDraw.setXscale(minX, maxX);
StdDraw.setYscale(minY, maxY);
StdDraw.setPenColor(Color.LIGHT_GRAY);

for (int i = 0; i <= n; i+=cellSize) {
		//line(x0, y0, x1, y2)
		StdDraw.line(i, y0, i, y2);
}

for (int i = 0; i <= n; i+=cellSize) {
		//line(x0, y0, x1, y2)
		StdDraw.line(x0, i, x1, i);
}
```

####

#### Running: The Game of Life

![](/files/-M_0_jukFmBVZ6UypMXf)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nissan-goldberg.gitbook.io/java101/exercises/exercise-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
