Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please finsh this code like asked ontop Java: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in);
Please finsh this code like asked ontop Java:
import java.util.Scanner; public class Main { 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 Here is the starter code for Game of Life, with most of the logic that implements the rules removed. 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started