Question: Java Programming language Please help me with adding code on TO DO* parts, I'm stuck on them and still learning. Here is the starter code

Java Programming language

Please help me with adding code on "TO DO*" parts, I'm stuck on them and still learning.

Here is the starter code for Game of Life, with most of the logic that implements the rules removed:

/** * Simple implementation of John Conway's Game of Life. * Starts with random seed and plays out on bounded grid * (without wrap-around). * * User interactions: * ENTER to evolve * 'A' to add a live cell * 'N' to display neighbor counts for each cell * 'Q' to end game * * TO DO: * I removed much of the implementation; look for * "TO DO" throughout the code. * * Also, you may want to add other interactions, for example: * - removing (or killing) a cell * - toggling a cell (change its state) * - adding a bunch of live cells at random locations in one step * * Other ideas: * - Change the program so that the user can enter the size of the * grid and the initial density of live cells, either through * console input or as commandline args. * - Display the number of live cells and the number of evolutions. * */ import java.util.Scanner; public class GameOfLife { public static void main(String[] args) { Scanner input = new Scanner(System.in); // user commands final String QUIT = "Q"; final String ADD_CELL = "A"; final String DISPLAY_NEIGHBOR_COUNTS = "N"; // user input is stored here String command; // world setup final int GRID_HEIGHT = 20 + 2; // '+2' is a border of empty final int GRID_WIDTH = 40 + 2; // cells around the grid -- it makes // for simple/easy implementation final double SEED_DENSITY = 0.6; boolean[][] cells = randomSeed(GRID_HEIGHT, GRID_WIDTH, SEED_DENSITY); boolean keepGoing = true; do { displayGrid(cells); command = input.nextLine().trim().toUpperCase(); if(command.startsWith(QUIT)) { keepGoing = false;

} else if(command.startsWith(ADD_CELL)) { System.out.print("row: "); int row = input.nextInt(); System.out.print("col: "); int col = input.nextInt(); input.nextLine(); addCell(cells, row, col); } else if(command.startsWith(DISPLAY_NEIGHBOR_COUNTS)) { displayNeighborCounts(cells); } else { cells = evolve(cells); } } while(keepGoing); } /* Takes current generation of cells and returns the next generation. Cells in top and bottom row and leftmost and rightmost columns of grid (i.e. border cells) do not evolve TO DO: Right now only the first rule is implemented -- you add code for the rest. */ public static boolean[][] evolve(boolean[][] cells) { boolean[][] nextGen = new boolean[cells.length][cells[0].length]; for(int row = 1; row

or crash the game by specifying location outside the grid. Modify this method to prevent either of these from happening; if row or col are either border or outside the grid display a message letting the user know that the location is out of bounds. */ public static void addCell(boolean[][] grid, int row, int col) { grid[row][col] = true; } /* Counts and returns the number of live cells (true is live) surrounding the cell at specified location. If X is the cell at (row, col), its neighbors are shown with 'n': n n n n X n n n n Thus the number returned must be in [0, 8] TO DO: Right now it just returns 0 for each cell, making all the cells die out. Prevent this cell massacre!!!! */ public static int countNeighbors(boolean[][] grid, int row, int col) { int num = 0; return num; } /* Returns grid with specified height and width, randomly seeded with live cells. The probability that a non-border cell is alive is equal to density. */ public static boolean[][] randomSeed(int height, int width, double density) { boolean[][] grid = new boolean[height][width]; for(int row = 1; row

for (int row = 1; row

Java Programming language Please help me with adding code on "TO DO*"

TASK: Look for TO DOs throughout the code; the task you must complete is to add this missing code so that the program plays the game correctly -- producing this "minimum viable product" should be doable by the end of the lab, though you may need to review boolean expression and array syntax in Java. Submission: - Your version of GameOfLife.java - Screenshot showing that neighbor counts are correctly displayed. RECOMMENDED TASKS: I have also put some suggestions in the comments for tasks that you do not need to complete for the lab, but might want to anyway just for the sake of practice. This does not have to appear in your submission

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!