Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code in Java please, *Do not use CharToArray* Please explain how you implemented the code so I have a better understanding Code uses the rules

Code in Java please,

*Do not use CharToArray*

Please explain how you implemented the code so I have a better understanding

Code uses the rules of Conway's Game of Life

In case you are not familiar with Conways Game of Life, please visit the following page for full details of all rules: https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life. The traditional game of life is played on a flat board (2D array). Your mission is that, given any configuration of a game-of-life, your implementation should allow any user to initialize the 2D array with any population and make it evolve over any given number of time steps.

Attributes:

o Size: int

o Board: int[][] this is a square board, same number of rows and columns

o Previous: int[][] this 2D array will store a copy of the game of life board.

Constructors:

o Default constructor o Constructor that takes a size as input (this will be the number of rows as well as

the number of columns of your board and previous) o Constructor that take a 2D array as an input (its size will be the size of the

board and previous; its content is to be copied into previous)

Getter:

o getBoard returns the current board

oneStep:

o Takes no parameter and is a void method o It consists in transforming the current board into its next shape (board at next

time stamp).

neighbors:

o Takes two indices (representing a row index and a column index). o Computes the number of neighbors the corresponding cell on the board has.

evolution: o Takes an integer n, which represents the number of evolution steps we need to

conduct. o Transforms the board into the board after n steps of evolution (i.e., n

successive calls to oneStep). Note: you can use more methods (as helper methods for the above methods).

However, you need to stick at least to the ones above.

You have to test that your implementation of the game of life is correct. You are expected to do so using JUnit testing, in a file called GOLTester.java. In this file, you have to test the following class methods of the GameOfLife type (5 tests at least per method):

  • neighbors(int, int)

  • oneStep()

  • evolution(int)

    In particular, you should test the behavior of your two versions of the game of life on at least the following boards:

image text in transcribed

public class GameOfLife {

/* Attributes ****************************************************************/ /* Complete with attributes as described in the lab assignment * Your attributes should be private. */ /* Constructors ***************************************************************/ /* Default constructor: given to you */ public GameOfLife() {} /* Complete this code: * This constructor takes the size of the board as input * It initializes the size of the game of life to the value of the input. * It creates 2 square boards of this size: board and previous */ public GameOfLife(int size) { // COMPLETE CODE HERE } /* Complete this code: * This constructor takes a board as input * It initializes the size of the game of life to the size of the input board. * It creates 2 square boards of this size: board and previous, both of the same size as the input board B. * It initializes previous to the content of B. */ public GameOfLife(int[][] B) { // COMPLETE CODE HERE } /* Accessor / Getter *************************************************************/ /* Complete this code */ public int[][] getBoard() { // COMPLETE CODE HERE } /* GIVEN TO YOU: DO NOT MODIFY: * One step of evolution of the whole board: * The method oneStep takes the current board and modifies it so that the new content * reflects the state of the game of life after one step of evolution. */ public void oneStep() { for (int i=0; i

if (previous[i][j] == 0 && neighbors == 3) board[i][j] = 1; else if (previous[i][j] == 1) { if (neighbors > 3 || neighbors

/* Complete this method: * This method runs numberOfSteps evolution steps */ public void evolution(int numberOfSteps) { // COMPLETE CODE HERE } /************* Misc. Methods **********************************/ /* GIVEN TO YOU: DO NOT MODIFY: * make a copy of the current board so the current board can be updated */ public void copyToPrevious() { for (int i=0; i

/* GIVEN TO YOU: DO NOT MODIFY: * prints the current board */ public void printBoard() { for (int i=0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions

Question

=+h. Do all of the related materials project one cohesive message?

Answered: 1 week ago

Question

=+5 Does this case provide an example of the future for IHRM?

Answered: 1 week ago