Game of Life Simulation

This is Exercise 2.4 the text. Write a multi-class sequential Java program that simulates the game of life. The simulation occurs on an M-by-N rectangular array of cells. Each cell has only two values: 0 and 1. Each cell has eight neighbors: up, down, left, right, and four diagonally. Cells on the four edges of the grid have fewer than eight neighbors, of course. If the grid is declared as

   int[][] grid = new int[N][N];
then the neighbors of an interior cell grid[i][j] are
   grid[i-1][j], grid[i+1][j], grid[i][j-1], grid[i][j+1],
   grid[i-1][j-1], grid[i-1][j+1], grid[i+1][j-1], grid[i+1][j+1]

The game works like this. Fill the grid with the initial values. Then for each cell in the grid, compute the new value that the cell becomes in the next generation of the game. All changes occur simultaneously, called a generation.

Input Data

The input data to your Java program is

If the only input data is maxGenerations, then initialize the grid to random values (0 or 1). You may read input data from the keyboard or the command line, whichever you find more convenient. Remember to check for illegal input values, like negative numbers or cell initial values that are not 0 or 1.

Here are some sample input data sets to try. This initial population dies out.

0 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 0
This initial population dies more slowly.
0 0 0 0 0
0 1 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 0 0
This initial population reaches a stable state.
0 0 0 0 0
0 1 1 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0
This initial population oscillates.
0 0 0 0 0
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0
0 0 0 0 0

Animate your program using XtangoAnimator.