[JAVA] I'm having a bit of trouble trying to get my code to work. Please help me fix my code and help me make the actual board appear. Below I have attached instructions and the files that the program must be able to access. I have also included my own code. Thank you.

[INSTRUCTIONS]

Write a program titled “YourLastName_GameOfLife” which will implement Conway's Game of Life. Life is a simulation of simple one-celled organisms and therefore typically played on a 2D grid of square cells. Each cell has two possible states: dead or alive. To calculate each new generation of the board, use the following rules:

For spaces already “alive”:

– Each cell with less than two neighbors, who are alive, dies of loneliness in the next generation.

– Each cell with more than three neighbors, who are alive, dies of overpopulation in the next generation.

– Each cell with two or three neighbors, who are alive, continues to be alive in the next generation.

For spaces already “dead”:

– Each cell with three neighbors, who are alive, comes to life in the next generation.

Note: Every cell has eight neighbors which are the cells that are diagonally, vertically, or horizontally adjacent.

For your program, use a 2D char array to represent the board. Use '0' to represent dead cells of the board and 'X' to represent cells which are alive. Your program will load game board data from a file to begin the game, with the first line of the input file consisting of two ints representing the number of columns and rows for the board.

[CODE MUST INCLUDE]

Methods to implement:

– The constructor which initializes a new game board by prompting the user for the file name and loading the game board data from the file.

– public int getColumns(), return the number of columns in the game board.

– public int getRows(), return the number of rows in the game board.

– public int getCell(int column, int row), get the value of the cell at given column and row, returning 0 if either the column or the row is outside the bounds of the game board.

– public void setCell(int column, int row, int value), set the value of the cell at given column and row. This method does not have to handle out-of-bounds column or row numbers.

– public void computeNextGeneration(int generation), creates a temporary 2D array to compute the next iteration of the board containing the next generation of organisms, as determined by the Rules of Life. Then updates the board to represent the next generation. The argument passed in represents the number of generations the user wants to compute. To compute each generation, the method should recursively call itself and decrement the integer until it terminates when there are no more generations left to compute.

– public void print(), which prints out the board to the console.

The program should prompt the user for the file name and how many generations to compute, then print out each generation to the screen.

[EXAMPLE OF COMPILED CODE]

Script started on Thu Sep 26 10:23:58 2015

% java Smith_GameOfLife

Enter file name: sample.life

Enter how many generations to compute: 1

Generation 1

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 X X X 0 0 0

0 0 X 0 0 0 0 X 0 0

0 0 X 0 0 0 0 X 0 0

0 0 X 0 0 0 0 X 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 X X X 0 0 0

0 0 0 0 0 0 0 0 0 0

% exit

script done on November 12 2222

Run the program with one of the input files provided as well as one of your own (with a reasonable amount of generations) and capture all interaction in a file using the script command.

Programs provided:

blinkers.life (name of file)

52 31
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X X X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 X 0 0 X X X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X X X 0 0 0
0 0 0 0 0 0 0 0 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X 0 0 0 0 0 0 0 0 0 0 0
0 0 0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 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

[MY CODE]

public class GameOfLife {

public int countNeighbors(char[][] convoyBoard, int getRows, int getColumns) {

int counting = 0;

int [][] neighbors = {

{ getRows-1, getColumns-1 },

{ getRows-1, getColumns },

{ getRows-1, getColumns+1 },

{ getRows, getColumns-1 },

{ getRows, getColumns+1 },

{ getRows+1, getColumns-1},

{ getRows+1, getColumns },

{ getRows+1, getColumns+1 }

   };

for (int j[]: neighbors) {

try {

if (convoyBoard[j[0]][j[1]] == 'X' ) {

counting++;

} // end if   

} // end try

catch (ArrayIndexOutOfBoundsException exep) { /* System.out.println(StackTrace);*/ }

} // end for

return counting;

} // end function counting neighbors

public static void main(String[] args) {

// TODO code application logic here

Scanner scnr = new Scanner(System.in);

String fileName;

System.out.println(“Enter file name:”);

fileName = scnr.nextLine();

fileName = “E:/Files/blnkrLife.txt”;

System.out.println(“Enter how many generations to compute:”);

int gen;

gen = scnr.nextInt();

char[][] nextConvoyBoard = { //sample board  

{ '0','0','X','0','X','0','0' },

{ 'X','X','X','0','X','0','X' },

{ '0','X','0','X','0','X','X' }

};

for (int i = 1; i

System.out.println(“Generation ” + i + ” : “);

}

}   

}

Enter file name: blinkers.life Enter how many generations to compute: 4. Generation 1 : Generation 2 : Generation 3 : Generation 4 :

"Get 15% discount on your first 3 orders with us"
Use the following coupon
"FIRST15"

Order Now